forked from lix-project/lix
Add 'nix profile wipe-history' command
This commit is contained in:
parent
f359b9981b
commit
4b738fc7a9
|
@ -126,9 +126,9 @@ void deleteGeneration(const Path & profile, GenerationNumber gen)
|
|||
static void deleteGeneration2(const Path & profile, GenerationNumber gen, bool dryRun)
|
||||
{
|
||||
if (dryRun)
|
||||
printInfo(format("would remove profile version %1%") % gen);
|
||||
notice("would remove profile version %1%", gen);
|
||||
else {
|
||||
printInfo(format("removing profile version %1%") % gen);
|
||||
notice("removing profile version %1%", gen);
|
||||
deleteGeneration(profile, gen);
|
||||
}
|
||||
}
|
||||
|
|
20
src/nix/profile-wipe-history.md
Normal file
20
src/nix/profile-wipe-history.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
* Delete all versions of the default profile older than 100 days:
|
||||
|
||||
```console
|
||||
# nix profile wipe-history --profile /tmp/profile --older-than 100d
|
||||
removing profile version 515
|
||||
removing profile version 514
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
This command deletes non-current versions of a profile, making it
|
||||
impossible to roll back to these versions. By default, all non-current
|
||||
versions are deleted. With `--older-than` *N*`d`, all non-current
|
||||
versions older than *N* days are deleted.
|
||||
|
||||
)""
|
|
@ -575,6 +575,44 @@ struct CmdProfileRollback : virtual StoreCommand, MixDefaultProfile, MixDryRun
|
|||
}
|
||||
};
|
||||
|
||||
struct CmdProfileWipeHistory : virtual StoreCommand, MixDefaultProfile, MixDryRun
|
||||
{
|
||||
std::optional<std::string> minAge;
|
||||
|
||||
CmdProfileWipeHistory()
|
||||
{
|
||||
addFlag({
|
||||
.longName = "older-than",
|
||||
.description =
|
||||
"Delete versions older than the specified age. *age* "
|
||||
"must be in the format *N*`d`, where *N* denotes a number "
|
||||
"of days.",
|
||||
.labels = {"age"},
|
||||
.handler = {&minAge},
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "delete non-current versions of a profile";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "profile-wipe-history.md"
|
||||
;
|
||||
}
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
if (minAge)
|
||||
deleteGenerationsOlderThan(*profile, *minAge, dryRun);
|
||||
else
|
||||
deleteOldGenerations(*profile, dryRun);
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdProfile : NixMultiCommand
|
||||
{
|
||||
CmdProfile()
|
||||
|
@ -586,6 +624,7 @@ struct CmdProfile : NixMultiCommand
|
|||
{"diff-closures", []() { return make_ref<CmdProfileDiffClosures>(); }},
|
||||
{"history", []() { return make_ref<CmdProfileHistory>(); }},
|
||||
{"rollback", []() { return make_ref<CmdProfileRollback>(); }},
|
||||
{"wipe-history", []() { return make_ref<CmdProfileWipeHistory>(); }},
|
||||
})
|
||||
{ }
|
||||
|
||||
|
|
Loading…
Reference in a new issue