Giter Site home page Giter Site logo

Comments (2)

matjam avatar matjam commented on July 28, 2024

Is the following a correct explanation of the semantics?

  1. Create a file at path dir+"."+name called tmplock. Fail if unable to create. (potential race condition here, I suggest it be dir+"."+name+random_stuff_or_pid_or_something)
  2. Write the current pid to tmplock, fail if unable to write.
  3. Hard link tmplock to dir+name. Ignore failure to link.
  4. Stat tmplock by name (should still be dir+"."+name). It should still exist, error if not.
  5. Stat the real lock dir+name. Should exist. Error if doesn't.
  6. Make sure that both the tmplock and the new lock are the same file.
  7. Get the owner of the lock.
    etc

from lockfile.

nightlyone avatar nightlyone commented on July 28, 2024

@matjam Thanks for taking the time to analyse the code deeply.

Is the following a correct explanation of the semantics?

  1. Create a file at path dir+"."+name called tmplock. Fail if unable to create. (potential race condition here, I suggest it be dir+"."+name+random_stuff_or_pid_or_something)

ioutil.TempFile takes care of the "random_stuff_or_pid_or_something" for me. So consider it done 🙂

  1. Write the current pid to tmplock, fail if unable to write.

Yes.

  1. Hard link tmplock to dir+name. Ignore failure to link.

Your observation of the existing code is correct.

Intention here was to only ignore the failure to create a link due to the destination already existing.
Ignoring every error here was the bug that made analysis of golang/dep#913 harder than necessary. This imprecise error handling is fixed by #21 .

  1. Stat tmplock by name (should still be dir+"."+name). It should still exist, error if not.
  2. Stat the real lock dir+name. Should exist. Error if doesn't.
  3. Make sure that both the tmplock and the new lock are the same file.
  4. Get the owner of the lock.
    etc

correct.

from lockfile.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.