From 7a02d954186d6ba1ea41d9917d63f9fab84736b3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 21 Nov 2003 16:05:19 +0000 Subject: [PATCH] * Remove lock files after building. --- src/libstore/normalise.cc | 5 +++++ src/libstore/pathlocks.cc | 14 +++++++++++++- src/libstore/pathlocks.hh | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc index c531e6784..db85c3b5b 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 3ecbbbcba..c057edce1 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::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 ce61386d6..606ae91c0 100644 --- a/src/libstore/pathlocks.hh +++ b/src/libstore/pathlocks.hh @@ -14,10 +14,12 @@ class PathLocks private: list fds; Paths paths; + bool deletePaths; public: PathLocks(const PathSet & _paths); ~PathLocks(); + void setDeletion(bool deletePaths); };