1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 15:31:47 +02:00

* `--min-age' flag in nix-store and nix-collect-garbage to only delete

unreachable paths that haven't been used for N hours.  For instance,
  `nix-collect-garbage --min-age 168' only deletes paths that haven't
  been accessed in the last week.

  This is useful for instance in the build farm where many derivations
  can be shared between consecutive builds, and we wouldn't want a
  garbage collect to throw them all away.  We could of course register
  them as roots, but then we'd to unregister them at some point, which
  would be a pain to manage.  The `--min-age' flag gives us a sort of
  MRU caching scheme.

  BUG: this really shouldn't be in gc.cc since that violates
  mechanism/policy separation.
This commit is contained in:
Eelco Dolstra 2004-08-25 16:54:08 +00:00
parent fdec72c6cc
commit eb233e728f
6 changed files with 70 additions and 17 deletions

View file

@ -212,17 +212,22 @@ static void opIsValid(Strings opFlags, Strings opArgs)
static void opGC(Strings opFlags, Strings opArgs)
{
if (opFlags.size() != 1) throw UsageError("missing flag");
if (!opArgs.empty())
throw UsageError("no arguments expected");
/* Do what? */
string flag = opFlags.front();
enum { soPrintLive, soPrintDead, soDelete } subOp;
if (flag == "--print-live") subOp = soPrintLive;
else if (flag == "--print-dead") subOp = soPrintDead;
else if (flag == "--delete") subOp = soDelete;
else throw UsageError(format("bad sub-operation `%1%' in GC") % flag);
time_t minAge = 0;
for (Strings::iterator i = opFlags.begin();
i != opFlags.end(); ++i)
if (*i == "--print-live") subOp = soPrintLive;
else if (*i == "--print-dead") subOp = soPrintDead;
else if (*i == "--delete") subOp = soDelete;
else if (*i == "--min-age") {
if (opArgs.size() == 0)
throw UsageError("`--min-age' requires an argument");
istringstream st(opArgs.front());
st >> minAge;
if (!st) throw Error("number expected");
}
else throw UsageError(format("bad sub-operation `%1%' in GC") % *i);
Paths roots;
while (1) {
@ -240,7 +245,7 @@ static void opGC(Strings opFlags, Strings opArgs)
return;
}
PathSet dead = findDeadPaths(live);
PathSet dead = findDeadPaths(live, minAge * 3600);
if (subOp == soPrintDead) {
for (PathSet::iterator i = dead.begin(); i != dead.end(); ++i)