nix-store --gc: Make ‘--max-freed 0’ do the right thing

That is, delete almost nothing (it will still remove unused links from
/nix/store/.links).
This commit is contained in:
Eelco Dolstra 2012-08-01 19:14:30 -04:00
parent 1df702d347
commit 967d066d8e
4 changed files with 6 additions and 7 deletions

View file

@ -550,7 +550,7 @@ bool LocalStore::tryToDelete(GCState & state, const Path & path)
} else
deleteGarbage(state, path);
if (state.options.maxFreed && state.results.bytesFreed + state.bytesInvalidated > state.options.maxFreed) {
if (state.results.bytesFreed + state.bytesInvalidated > state.options.maxFreed) {
printMsg(lvlInfo, format("deleted or invalidated more than %1% bytes; stopping") % state.options.maxFreed);
throw GCLimitReached();
}
@ -675,7 +675,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
throw Error(format("cannot delete path `%1%' since it is still alive") % *i);
}
} else {
} else if (options.maxFreed > 0) {
if (shouldDelete(state.options.action))
printMsg(lvlError, format("deleting garbage..."));

View file

@ -2,7 +2,7 @@
#include "globals.hh"
#include "util.hh"
#include <limits.h>
#include <climits>
namespace nix {
@ -12,7 +12,7 @@ GCOptions::GCOptions()
{
action = gcDeleteDead;
ignoreLiveness = false;
maxFreed = 0;
maxFreed = ULLONG_MAX;
}

View file

@ -48,8 +48,7 @@ struct GCOptions
/* For `gcDeleteSpecific', the paths to delete. */
PathSet pathsToDelete;
/* Stop after at least `maxFreed' bytes have been freed. 0 means
no limit. */
/* Stop after at least `maxFreed' bytes have been freed. */
unsigned long long maxFreed;
GCOptions();

View file

@ -583,7 +583,7 @@ static void opGC(Strings opFlags, Strings opArgs)
else if (*i == "--delete") options.action = GCOptions::gcDeleteDead;
else if (*i == "--max-freed") {
long long maxFreed = getIntArg<long long>(*i, i, opFlags.end());
options.maxFreed = maxFreed >= 1 ? maxFreed : 1;
options.maxFreed = maxFreed >= 0 ? maxFreed : 0;
}
else throw UsageError(format("bad sub-operation `%1%' in GC") % *i);