From eadb86f44726e12988d5f21b47e4c54b49b2092b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 21 Aug 2015 13:57:53 +0200 Subject: [PATCH] nix-collect-garbage: Revive --max-freed Fixes #609. --- src/libstore/store-api.cc | 10 ---------- src/libstore/store-api.hh | 9 ++++----- src/nix-collect-garbage/nix-collect-garbage.cc | 10 +++++++--- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index bb0bc0933..a73ebd824 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -2,20 +2,10 @@ #include "globals.hh" #include "util.hh" -#include - namespace nix { -GCOptions::GCOptions() -{ - action = gcDeleteDead; - ignoreLiveness = false; - maxFreed = ULLONG_MAX; -} - - bool isInStore(const Path & path) { return isInDir(path, settings.nixStore); diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index d04a040bb..235017503 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -4,6 +4,7 @@ #include "serialise.hh" #include +#include #include #include @@ -36,21 +37,19 @@ struct GCOptions gcDeleteSpecific, } GCAction; - GCAction action; + GCAction action{gcDeleteDead}; /* If `ignoreLiveness' is set, then reachability from the roots is ignored (dangerous!). However, the paths must still be unreferenced *within* the store (i.e., there can be no other store paths that depend on them). */ - bool ignoreLiveness; + bool ignoreLiveness{false}; /* For `gcDeleteSpecific', the paths to delete. */ PathSet pathsToDelete; /* Stop after at least `maxFreed' bytes have been freed. */ - unsigned long long maxFreed; - - GCOptions(); + unsigned long long maxFreed{std::numeric_limits::max()}; }; diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc index 253c0b537..bb4789aea 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/nix-collect-garbage/nix-collect-garbage.cc @@ -50,11 +50,12 @@ void removeOldGenerations(std::string dir) int main(int argc, char * * argv) { bool removeOld = false; - Strings extraArgs; return handleExceptions(argv[0], [&]() { initNix(); + GCOptions options; + parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { if (*arg == "--help") showManPage("nix-collect-garbage"); @@ -66,8 +67,12 @@ int main(int argc, char * * argv) deleteOlderThan = getArg(*arg, arg, end); } else if (*arg == "--dry-run") dryRun = true; + else if (*arg == "--max-freed") { + long long maxFreed = getIntArg(*arg, arg, end, true); + options.maxFreed = maxFreed >= 0 ? maxFreed : 0; + } else - extraArgs.push_back(*arg); + return false; return true; }); @@ -77,7 +82,6 @@ int main(int argc, char * * argv) // Run the actual garbage collector. if (!dryRun) { store = openStore(false); - GCOptions options; options.action = GCOptions::gcDeleteDead; GCResults results; PrintFreed freed(true, results);