diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-12-12 17:03:18 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-12-12 17:03:18 +0000 |
commit | 0008b0006db59ea8fccfe041cf8d87f05abb427d (patch) | |
tree | 70adf7ea0596a5128c7e2f50fbed2fdae5510cea /src | |
parent | ac36c6cd44e8f46573ce3df0749d2f062fa35f3b (diff) |
* Simplify deleting .lock files in /nix/store: just don't delete them
if they belong a path that's currently being built. This gets rid
of some Cygwin-specific code.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/gc.cc | 48 | ||||
-rw-r--r-- | src/nix-store/nix-store.cc | 2 |
2 files changed, 19 insertions, 31 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 3621b88d9..32cfbd022 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -476,23 +476,6 @@ void LocalStore::gcPath(const GCOptions & options, GCResults & results, if (!pathExists(path)) return; -#ifndef __CYGWIN__ - AutoCloseFD fdLock; - - /* Only delete a lock file if we can acquire a write lock on it. - That means that it's either stale, or the process that created - it hasn't locked it yet. In the latter case the other process - will detect that we deleted the lock, and retry (see - pathlocks.cc). */ - if (path.size() >= 5 && string(path, path.size() - 5) == ".lock") { - fdLock = openLockFile(path, false); - if (fdLock != -1 && !lockFile(fdLock, ltWrite, false)) { - debug(format("skipping active lock `%1%'") % path); - return; - } - } -#endif - /* Okay, it's safe to delete. */ unsigned long long bytesFreed, blocksFreed; deleteFromStore(path, bytesFreed, blocksFreed); @@ -513,12 +496,6 @@ void LocalStore::gcPath(const GCOptions & options, GCResults & results, throw GCLimitReached(); } } - -#ifndef __CYGWIN__ - if (fdLock != -1) - /* Write token to stale (deleted) lock file. */ - writeFull(fdLock, (const unsigned char *) "d", 1); -#endif } @@ -569,7 +546,7 @@ struct CachingAtimeComparator : public std::binary_function<Path, Path, bool> }; -string showTime(const string & format, time_t t) +static string showTime(const string & format, time_t t) { char s[128]; strftime(s, sizeof s, format.c_str(), localtime(&t)); @@ -577,6 +554,21 @@ string showTime(const string & format, time_t t) } +static bool isLive(const Path & path, const PathSet & livePaths, + const PathSet & tempRoots, const PathSet & tempRootsClosed) +{ + if (livePaths.find(path) != livePaths.end() || + tempRootsClosed.find(path) != tempRootsClosed.end()) return true; + + /* A lock file belonging to a path that we're building right + now isn't garbage. */ + if (hasSuffix(path, ".lock") && tempRoots.find(string(path, 0, path.size() - 5)) != tempRoots.end()) + return true; + + return false; +} + + void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) { bool gcKeepOutputs = @@ -691,9 +683,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) Paths entries = readDirectory(nixStore); foreach (Paths::iterator, i, entries) { Path path = canonPath(nixStore + "/" + *i); - if (livePaths.find(path) == livePaths.end() && - tempRootsClosed.find(path) == tempRootsClosed.end()) - storePaths.insert(path); + if (!isLive(path, livePaths, tempRoots, tempRootsClosed)) storePaths.insert(path); } } @@ -701,10 +691,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) foreach (PathSet::iterator, i, options.pathsToDelete) { assertStorePath(*i); storePaths.insert(*i); - if (livePaths.find(*i) != livePaths.end()) + if (isLive(*i, livePaths, tempRoots, tempRootsClosed)) throw Error(format("cannot delete path `%1%' since it is still alive") % *i); - if (tempRootsClosed.find(*i) != tempRootsClosed.end()) - throw Error(format("cannot delete path `%1%' since it is temporarily in use") % *i); } } diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 065d7d4c0..f6271d56a 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -96,7 +96,7 @@ static void opRealise(Strings opFlags, Strings opArgs) if (isDerivation(*i)) drvPaths.insert(*i); store->buildDerivations(drvPaths); - foreach (Strings::iterator, i,opArgs) + foreach (Strings::iterator, i, opArgs) cout << format("%1%\n") % realisePath(*i); } |