about summary refs log tree commit diff
path: root/src/libstore/gc.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2009-11-24T09·53+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2009-11-24T09·53+0000
commitf9e766db9875e7ab390df8d405d9719b279efe3c (patch)
tree387d670ef179f242ef66231a418e1673ab2e3c6a /src/libstore/gc.cc
parentca50c83fbb8f3bfbbcc60203a518d4e5a7aa8349 (diff)
* Randomise the order in which we delete entries to make the collector
  less biased towards deleting paths that come alphabetically first
  (e.g. /nix/store/000...).  This matters when using --max-freed etc.

Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r--src/libstore/gc.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 88ddad822baf..fc9791023a59 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -7,6 +7,7 @@
 
 #include <functional>
 #include <queue>
+#include <algorithm>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -590,7 +591,7 @@ bool LocalStore::tryToDelete(GCState & state, const Path & path)
         state.results.paths.insert(path);
     return false;
 }
-    
+
 
 void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
 {
@@ -646,13 +647,20 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
         printMsg(lvlError, format("reading the Nix store..."));
         Paths entries = readDirectory(nixStore);
 
+        /* Randomise the order in which we delete entries to make the
+           collector less biased towards deleting paths that come
+           alphabetically first (e.g. /nix/store/000...).  This
+           matters when using --max-freed etc. */
+        vector<Path> entries_(entries.begin(), entries.end());
+        random_shuffle(entries_.begin(), entries_.end());
+
         if (doDelete(state.options.action))
             printMsg(lvlError, format("deleting garbage..."));
         else
             printMsg(lvlError, format("determining live/dead paths..."));
     
         try {
-            foreach (Paths::iterator, i, entries)
+            foreach (vector<Path>::iterator, i, entries_)
                 tryToDelete(state, canonPath(nixStore + "/" + *i));
         } catch (GCLimitReached & e) {
         }