parent
1d29db2a9f
commit
eadb86f447
|
@ -2,20 +2,10 @@
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
GCOptions::GCOptions()
|
|
||||||
{
|
|
||||||
action = gcDeleteDead;
|
|
||||||
ignoreLiveness = false;
|
|
||||||
maxFreed = ULLONG_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool isInStore(const Path & path)
|
bool isInStore(const Path & path)
|
||||||
{
|
{
|
||||||
return isInDir(path, settings.nixStore);
|
return isInDir(path, settings.nixStore);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "serialise.hh"
|
#include "serialise.hh"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -36,21 +37,19 @@ struct GCOptions
|
||||||
gcDeleteSpecific,
|
gcDeleteSpecific,
|
||||||
} GCAction;
|
} GCAction;
|
||||||
|
|
||||||
GCAction action;
|
GCAction action{gcDeleteDead};
|
||||||
|
|
||||||
/* If `ignoreLiveness' is set, then reachability from the roots is
|
/* If `ignoreLiveness' is set, then reachability from the roots is
|
||||||
ignored (dangerous!). However, the paths must still be
|
ignored (dangerous!). However, the paths must still be
|
||||||
unreferenced *within* the store (i.e., there can be no other
|
unreferenced *within* the store (i.e., there can be no other
|
||||||
store paths that depend on them). */
|
store paths that depend on them). */
|
||||||
bool ignoreLiveness;
|
bool ignoreLiveness{false};
|
||||||
|
|
||||||
/* For `gcDeleteSpecific', the paths to delete. */
|
/* For `gcDeleteSpecific', the paths to delete. */
|
||||||
PathSet pathsToDelete;
|
PathSet pathsToDelete;
|
||||||
|
|
||||||
/* Stop after at least `maxFreed' bytes have been freed. */
|
/* Stop after at least `maxFreed' bytes have been freed. */
|
||||||
unsigned long long maxFreed;
|
unsigned long long maxFreed{std::numeric_limits<unsigned long long>::max()};
|
||||||
|
|
||||||
GCOptions();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,11 +50,12 @@ void removeOldGenerations(std::string dir)
|
||||||
int main(int argc, char * * argv)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
bool removeOld = false;
|
bool removeOld = false;
|
||||||
Strings extraArgs;
|
|
||||||
|
|
||||||
return handleExceptions(argv[0], [&]() {
|
return handleExceptions(argv[0], [&]() {
|
||||||
initNix();
|
initNix();
|
||||||
|
|
||||||
|
GCOptions options;
|
||||||
|
|
||||||
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
if (*arg == "--help")
|
if (*arg == "--help")
|
||||||
showManPage("nix-collect-garbage");
|
showManPage("nix-collect-garbage");
|
||||||
|
@ -66,8 +67,12 @@ int main(int argc, char * * argv)
|
||||||
deleteOlderThan = getArg(*arg, arg, end);
|
deleteOlderThan = getArg(*arg, arg, end);
|
||||||
}
|
}
|
||||||
else if (*arg == "--dry-run") dryRun = true;
|
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
|
else
|
||||||
extraArgs.push_back(*arg);
|
return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -77,7 +82,6 @@ int main(int argc, char * * argv)
|
||||||
// Run the actual garbage collector.
|
// Run the actual garbage collector.
|
||||||
if (!dryRun) {
|
if (!dryRun) {
|
||||||
store = openStore(false);
|
store = openStore(false);
|
||||||
GCOptions options;
|
|
||||||
options.action = GCOptions::gcDeleteDead;
|
options.action = GCOptions::gcDeleteDead;
|
||||||
GCResults results;
|
GCResults results;
|
||||||
PrintFreed freed(true, results);
|
PrintFreed freed(true, results);
|
||||||
|
|
Loading…
Reference in a new issue