mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
* Fix and simplify the garbage collector (it's still not concurrent,
though). In particular it's now much easier to register a GC root. Just place a symlink to whatever store path it is that you want to keep in /nix/var/nix/gcroots.
This commit is contained in:
parent
59682e6188
commit
c505702265
10 changed files with 124 additions and 109 deletions
|
@ -1,12 +1,68 @@
|
|||
#include "globals.hh"
|
||||
#include "gc.hh"
|
||||
|
||||
#include "build.hh"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void collectGarbage(const PathSet & roots, GCAction action,
|
||||
PathSet & result)
|
||||
{
|
||||
result.clear();
|
||||
|
||||
/* !!! TODO: Acquire an exclusive lock on the gcroots directory.
|
||||
This prevents the set of live paths from increasing after this
|
||||
point. */
|
||||
|
||||
/* Determine the live paths which is just the closure of the
|
||||
roots under the `references' relation. */
|
||||
PathSet livePaths;
|
||||
for (PathSet::const_iterator i = roots.begin(); i != roots.end(); ++i)
|
||||
computeFSClosure(canonPath(*i), livePaths);
|
||||
|
||||
if (action == gcReturnLive) {
|
||||
result = livePaths;
|
||||
return;
|
||||
}
|
||||
|
||||
/* !!! TODO: Try to acquire (without blocking) exclusive locks on
|
||||
the files in the `pending' directory. Delete all files for
|
||||
which we managed to acquire such a lock (since if we could get
|
||||
such a lock, that means that the process that owned the file
|
||||
has died). */
|
||||
|
||||
/* !!! TODO: Acquire shared locks on all files in the pending
|
||||
directories. This prevents the set of pending paths from
|
||||
increasing while we are garbage-collecting. Read the set of
|
||||
pending paths from those files. */
|
||||
|
||||
/* Read the Nix store directory to find all currently existing
|
||||
paths. */
|
||||
Strings storeNames = readDirectory(nixStore);
|
||||
|
||||
for (Strings::iterator i = storeNames.begin(); i != storeNames.end(); ++i) {
|
||||
Path path = canonPath(nixStore + "/" + *i);
|
||||
|
||||
if (livePaths.find(path) != livePaths.end()) {
|
||||
debug(format("live path `%1%'") % path);
|
||||
continue;
|
||||
}
|
||||
|
||||
debug(format("dead path `%1%'") % path);
|
||||
result.insert(path);
|
||||
|
||||
if (action == gcDeleteDead) {
|
||||
printMsg(lvlInfo, format("deleting `%1%'") % path);
|
||||
deleteFromStore(path);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void followLivePaths(Path nePath, PathSet & live)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue