diff options
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/normalise.cc | 5 | ||||
-rw-r--r-- | src/libstore/pathlocks.cc | 14 | ||||
-rw-r--r-- | src/libstore/pathlocks.hh | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc index c531e6784bcb..db85c3b5b879 100644 --- a/src/libstore/normalise.cc +++ b/src/libstore/normalise.cc @@ -256,6 +256,11 @@ Path normaliseStoreExpr(const Path & _nePath, PathSet pending) registerSuccessor(txn, nePath, nfPath); txn.commit(); + /* It is now safe to delete the lock files, since all future + lockers will see the successor; they will not create new lock + files with the same names as the old (unlinked) lock files. */ + outputLocks.setDeletion(true); + return nfPath; } diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 3ecbbbcbafd5..c057edce118b 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -43,6 +43,7 @@ static StringSet lockedPaths; /* !!! not thread-safe */ PathLocks::PathLocks(const PathSet & _paths) + : deletePaths(false) { /* Note that `fds' is built incrementally so that the destructor will only release those locks that we have already acquired. */ @@ -85,6 +86,17 @@ PathLocks::~PathLocks() for (list<int>::iterator i = fds.begin(); i != fds.end(); i++) close(*i); - for (Paths::iterator i = paths.begin(); i != paths.end(); i++) + for (Paths::iterator i = paths.begin(); i != paths.end(); i++) { + if (deletePaths) + /* This is not safe in general! */ + if (unlink(i->c_str()) != 0) + throw SysError(format("removing lock file `%1%'") % *i); lockedPaths.erase(*i); + } +} + + +void PathLocks::setDeletion(bool deletePaths) +{ + this->deletePaths = deletePaths; } diff --git a/src/libstore/pathlocks.hh b/src/libstore/pathlocks.hh index ce61386d6df0..606ae91c05a6 100644 --- a/src/libstore/pathlocks.hh +++ b/src/libstore/pathlocks.hh @@ -14,10 +14,12 @@ class PathLocks private: list<int> fds; Paths paths; + bool deletePaths; public: PathLocks(const PathSet & _paths); ~PathLocks(); + void setDeletion(bool deletePaths); }; |