diff options
Diffstat (limited to 'src/nix-collect-garbage/nix-collect-garbage.cc')
-rw-r--r-- | src/nix-collect-garbage/nix-collect-garbage.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc index c8dc9099ca09..3aa348581b19 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/nix-collect-garbage/nix-collect-garbage.cc @@ -4,6 +4,7 @@ #include "globals.hh" #include <iostream> +#include <cerrno> using namespace nix; @@ -28,7 +29,12 @@ void removeOldGenerations(std::string dir) auto type = i.type == DT_UNKNOWN ? getFileType(path) : i.type; if (type == DT_LNK && canWrite) { - auto link = readLink(path); + std::string link; + try { + link = readLink(path); + } catch (SysError & e) { + if (e.errNo == ENOENT) continue; + } if (link.find("link") != string::npos) { printMsg(lvlInfo, format("removing old generations of profile %1%") % path); if (deleteOlderThan != "") @@ -45,11 +51,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"); @@ -61,8 +68,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<long long>(*arg, arg, end, true); + options.maxFreed = maxFreed >= 0 ? maxFreed : 0; + } else - extraArgs.push_back(*arg); + return false; return true; }); @@ -71,8 +82,7 @@ int main(int argc, char * * argv) // Run the actual garbage collector. if (!dryRun) { - store = openStore(false); - GCOptions options; + auto store = openStore(); options.action = GCOptions::gcDeleteDead; GCResults results; PrintFreed freed(true, results); |