mirror of
https://github.com/NixOS/nix
synced 2025-06-30 11:43:15 +02:00
* Operation `--delete-generations' to delete generations of a
profile. Arguments are either generation number, or `old' to delete all non-current generations. Typical use: $ nix-env --delete-generations old $ nix-collect-garbage * istringstream -> string2Int.
This commit is contained in:
parent
c16be6ac92
commit
dcc433de47
8 changed files with 100 additions and 33 deletions
|
@ -643,10 +643,8 @@ static void opSwitchGeneration(Globals & globals,
|
|||
if (opArgs.size() != 1)
|
||||
throw UsageError(format("exactly one argument expected"));
|
||||
|
||||
istringstream str(opArgs.front());
|
||||
int dstGen;
|
||||
str >> dstGen;
|
||||
if (!str || !str.eof())
|
||||
if (!string2Int(opArgs.front(), dstGen))
|
||||
throw UsageError(format("expected a generation number"));
|
||||
|
||||
switchGeneration(globals, dstGen);
|
||||
|
@ -688,6 +686,49 @@ static void opListGenerations(Globals & globals,
|
|||
}
|
||||
|
||||
|
||||
static void deleteGeneration2(const Path & profile, unsigned int gen)
|
||||
{
|
||||
printMsg(lvlInfo, format("removing generation %1%") % gen);
|
||||
deleteGeneration(profile, gen);
|
||||
}
|
||||
|
||||
|
||||
static void opDeleteGenerations(Globals & globals,
|
||||
Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||
|
||||
int curGen;
|
||||
Generations gens = findGenerations(globals.profile, curGen);
|
||||
|
||||
for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) {
|
||||
|
||||
if (*i == "old") {
|
||||
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j)
|
||||
if (j->number != curGen)
|
||||
deleteGeneration2(globals.profile, j->number);
|
||||
}
|
||||
|
||||
else {
|
||||
int n;
|
||||
if (!string2Int(*i, n) || n < 0)
|
||||
throw UsageError(format("invalid generation specifier `%1%'") % *i);
|
||||
bool found = false;
|
||||
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j) {
|
||||
if (j->number == n) {
|
||||
deleteGeneration2(globals.profile, j->number);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
printMsg(lvlError, format("generation %1% does not exist") % n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void opDefaultExpr(Globals & globals,
|
||||
Strings opFlags, Strings opArgs)
|
||||
{
|
||||
|
@ -750,6 +791,8 @@ void run(Strings args)
|
|||
op = opRollback;
|
||||
else if (arg == "--list-generations")
|
||||
op = opListGenerations;
|
||||
else if (arg == "--delete-generations")
|
||||
op = opDeleteGenerations;
|
||||
else if (arg == "--dry-run") {
|
||||
printMsg(lvlInfo, "(dry run; not doing anything)");
|
||||
globals.dryRun = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue