diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-09-17 10:02:55 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-09-17 10:02:55 +0000 |
commit | 7ab68961e4d7c30485efde1fb9dcb6edbdea9b5c (patch) | |
tree | 2bb1faf9cb583276240ac9e9fa940205202bec39 /src/nix-store | |
parent | 2b2aa8a820b10aeaf8bb8f1eb70937d04869c045 (diff) | |
download | guix-7ab68961e4d7c30485efde1fb9dcb6edbdea9b5c.tar.gz |
* Garbage collector: added an option `--use-atime' to delete paths in
order of ascending last access time. This is useful in conjunction with --max-freed or --max-links to prefer deleting non-recently used garbage, which is good (especially in the build farm) since garbage may become live again. The code could easily be modified to accept other criteria for ordering garbage by changing the comparison operator used by the priority queue in collectGarbage().
Diffstat (limited to 'src/nix-store')
-rw-r--r-- | src/nix-store/nix-store.cc | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 0030745b46..2712d90602 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -501,17 +501,14 @@ static string showBytes(unsigned long long bytes, unsigned long long blocks) struct PrintFreed { - bool show, dryRun; + bool show; const GCResults & results; - PrintFreed(bool show, bool dryRun, const GCResults & results) - : show(show), dryRun(dryRun), results(results) { } + PrintFreed(bool show, const GCResults & results) + : show(show), results(results) { } ~PrintFreed() { if (show) - cout << format( - (dryRun - ? "%1% would be freed\n" - : "%1% freed\n")) + cout << format("%1% freed\n") % showBytes(results.bytesFreed, results.blocksFreed); } }; @@ -525,19 +522,17 @@ static void opGC(Strings opFlags, Strings opArgs) GCResults results; /* Do what? */ - for (Strings::iterator i = opFlags.begin(); - i != opFlags.end(); ++i) + foreach (Strings::iterator, i, opFlags) if (*i == "--print-roots") options.action = GCOptions::gcReturnRoots; else if (*i == "--print-live") options.action = GCOptions::gcReturnLive; else if (*i == "--print-dead") options.action = GCOptions::gcReturnDead; else if (*i == "--delete") options.action = GCOptions::gcDeleteDead; else if (*i == "--max-freed") options.maxFreed = getIntArg(*i, i, opFlags.end()); else if (*i == "--max-links") options.maxLinks = getIntArg(*i, i, opFlags.end()); + else if (*i == "--use-atime") options.useAtime = true; else throw UsageError(format("bad sub-operation `%1%' in GC") % *i); - PrintFreed freed( - options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcReturnDead, - options.action == GCOptions::gcReturnDead, results); + PrintFreed freed(options.action == GCOptions::gcDeleteDead, results); store->collectGarbage(options, results); if (options.action != GCOptions::gcDeleteDead) @@ -554,17 +549,15 @@ static void opDelete(Strings opFlags, Strings opArgs) GCOptions options; options.action = GCOptions::gcDeleteSpecific; - for (Strings::iterator i = opFlags.begin(); - i != opFlags.end(); ++i) + foreach (Strings::iterator, i, opFlags) if (*i == "--ignore-liveness") options.ignoreLiveness = true; else throw UsageError(format("unknown flag `%1%'") % *i); - for (Strings::iterator i = opArgs.begin(); - i != opArgs.end(); ++i) + foreach (Strings::iterator, i, opArgs) options.pathsToDelete.insert(followLinksToStorePath(*i)); GCResults results; - PrintFreed freed(true, false, results); + PrintFreed freed(true, results); store->collectGarbage(options, results); } |