2021-01-10 22:20:02 +00:00
|
|
|
#include "command.hh"
|
|
|
|
#include "common-args.hh"
|
|
|
|
#include "shared.hh"
|
|
|
|
#include "store-api.hh"
|
2022-03-01 18:31:36 +00:00
|
|
|
#include "gc-store.hh"
|
2021-01-10 22:20:02 +00:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
struct CmdStoreGC : StoreCommand, MixDryRun
|
|
|
|
{
|
|
|
|
GCOptions options;
|
|
|
|
|
|
|
|
CmdStoreGC()
|
|
|
|
{
|
|
|
|
addFlag({
|
|
|
|
.longName = "max",
|
2021-01-13 13:18:04 +00:00
|
|
|
.description = "Stop after freeing *n* bytes of disk space.",
|
2021-01-10 22:20:02 +00: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
|
|
|
|
{
|
2022-03-08 17:45:19 +00:00
|
|
|
auto & gcStore = GcStore::require(*store);
|
2022-03-01 18:31:36 +00:00
|
|
|
|
2021-01-10 22:20:02 +00:00
|
|
|
options.action = dryRun ? GCOptions::gcReturnDead : GCOptions::gcDeleteDead;
|
|
|
|
GCResults results;
|
|
|
|
PrintFreed freed(options.action == GCOptions::gcDeleteDead, results);
|
2022-03-01 18:31:36 +00:00
|
|
|
gcStore.collectGarbage(options, results);
|
2021-01-10 22:20:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto rCmdStoreGC = registerCommand2<CmdStoreGC>({"store", "gc"});
|