nix-super/src/nix/store-gc.cc

48 lines
1.1 KiB
C++
Raw Normal View History

2021-01-11 00:20:02 +02:00
#include "command.hh"
#include "common-args.hh"
#include "shared.hh"
#include "store-api.hh"
#include "store-cast.hh"
#include "gc-store.hh"
2021-01-11 00:20:02 +02:00
using namespace nix;
struct CmdStoreGC : StoreCommand, MixDryRun
{
GCOptions options;
CmdStoreGC()
{
addFlag({
.longName = "max",
.description = "Stop after freeing *n* bytes of disk space.",
2021-01-11 00:20:02 +02:00
.labels = {"n"},
.handler = {&options.maxFreed}
});
}
std::string description() override
{
return "perform garbage collection on a Nix store";
}
std::string doc() override
{
return
#include "store-gc.md"
;
}
void run(ref<Store> store) override
{
auto & gcStore = require<GcStore>(*store);
2021-01-11 00:20:02 +02:00
options.action = dryRun ? GCOptions::gcReturnDead : GCOptions::gcDeleteDead;
GCResults results;
PrintFreed freed(options.action == GCOptions::gcDeleteDead, results);
gcStore.collectGarbage(options, results);
2021-01-11 00:20:02 +02:00
}
};
static auto rCmdStoreGC = registerCommand2<CmdStoreGC>({"store", "gc"});