about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-09-17T14·52+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-09-17T14·52+0000
commitf32fef1b075f63ecf8c7351c5e67d4dd95c0fb80 (patch)
treef43b345933e83b54ec1c0ffa59cadf8e3b851666 /src/libstore
parent4af2fdba6d709d0b9bb77dd58ceb6e16d6cd4cfa (diff)
* GC option `--max-atime' that specifies an upper limit to the last
  accessed time of paths that may be deleted.  Anything more recently
  used won't be deleted.  The time is specified in time_t,
  e.g. seconds since 1970-01-01 00:00:00 UTC; use `date +%s' to
  convert to time_t from the command line. 

  Example: to delete everything that hasn't been used in the last two
  months:

  $ nix-store --gc -v --max-atime $(date +%s -d "2 months ago")
  

Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/gc.cc18
-rw-r--r--src/libstore/store-api.cc1
-rw-r--r--src/libstore/store-api.hh4
3 files changed, 17 insertions, 6 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 729e7b345881..3621b88d9049 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -531,10 +531,11 @@ void LocalStore::gcPathRecursive(const GCOptions & options,
     startNest(nest, lvlDebug, format("looking at `%1%'") % path);
         
     /* Delete all the referrers first.  They must be garbage too,
-       since if they were in the closure of some live path, then this
-       path would also be in the closure.  Note that
-       deleteFromStore() below still makes sure that the referrer set
-       has become empty, just in case. */
+       since if they were live, then the current path would also be
+       live.  Note that deleteFromStore() below still makes sure that
+       the referrer set has become empty, just in case.  (However that
+       doesn't guard against deleting top-level paths that are only
+       reachable from GC roots.) */
     PathSet referrers;
     if (isValidPath(path))
         queryReferrers(path, referrers);
@@ -571,7 +572,7 @@ struct CachingAtimeComparator : public std::binary_function<Path, Path, bool>
 string showTime(const string & format, time_t t)
 {
     char s[128];
-    strftime(s, sizeof s, format.c_str(), gmtime(&t));
+    strftime(s, sizeof s, format.c_str(), localtime(&t));
     return string(s);
 }
 
@@ -766,7 +767,12 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
             while (!prioQueue.empty()) {
                 checkInterrupt();
                 Path path = prioQueue.top(); prioQueue.pop();
-                printMsg(lvlInfo, format("deleting `%1%' (last accessed %2%)") % path % showTime("%F %H:%M:%S", atimeComp.cache[path]));
+
+                if (options.maxAtime != (time_t) -1 &&
+                    atimeComp.lookup(path) > options.maxAtime)
+                    continue;
+                
+                printMsg(lvlInfo, format("deleting `%1%' (last accessed %2%)") % path % showTime("%F %H:%M:%S", atimeComp.lookup(path)));
 
                 PathSet references;
                 if (isValidPath(path)) references = queryReferencesNoSelf(path);
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index c9b6fb95955d..23631a3b8e9c 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -15,6 +15,7 @@ GCOptions::GCOptions()
     maxFreed = ULLONG_MAX;
     maxLinks = 0;
     useAtime = false;
+    maxAtime = (time_t) -1;
 }
 
 
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 3c32003cb49c..ed7e60146029 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -75,6 +75,10 @@ struct GCOptions
        atime. */
     bool useAtime;
 
+    /* Do not delete paths newer than `maxAtime'.  -1 means no age
+       limit. */
+    time_t maxAtime;
+
     GCOptions();
 };