about summary refs log tree commit diff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-09-17T10·02+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-09-17T10·02+0000
commit7ab68961e4d7c30485efde1fb9dcb6edbdea9b5c (patch)
tree2bb1faf9cb583276240ac9e9fa940205202bec39 /src/nix-store/nix-store.cc
parent2b2aa8a820b10aeaf8bb8f1eb70937d04869c045 (diff)
* 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/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 0030745b4627..2712d90602ed 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);
 }