Skip to content

Commit

Permalink
nix-collect-garbage: Revive --max-freed
Browse files Browse the repository at this point in the history
Fixes NixOS#609.
  • Loading branch information
edolstra committed Aug 21, 2015
1 parent 1d29db2 commit eadb86f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
10 changes: 0 additions & 10 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@
#include "globals.hh"
#include "util.hh"

#include <climits>


namespace nix {


GCOptions::GCOptions()
{
action = gcDeleteDead;
ignoreLiveness = false;
maxFreed = ULLONG_MAX;
}


bool isInStore(const Path & path)
{
return isInDir(path, settings.nixStore);
Expand Down
9 changes: 4 additions & 5 deletions src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "serialise.hh"

#include <string>
#include <limits>
#include <map>
#include <memory>

Expand Down Expand Up @@ -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<unsigned long long>::max()};
};


Expand Down
10 changes: 7 additions & 3 deletions src/nix-collect-garbage/nix-collect-garbage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<long long>(*arg, arg, end, true);
options.maxFreed = maxFreed >= 0 ? maxFreed : 0;
}
else
extraArgs.push_back(*arg);
return false;
return true;
});

Expand All @@ -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);
Expand Down

0 comments on commit eadb86f

Please sign in to comment.