nix-env --delete-generations: Support --dry-run flag

Fixes #43.
This commit is contained in:
Eelco Dolstra 2012-09-13 18:05:04 -04:00
parent 1bda006b74
commit 9fd9dedf12
2 changed files with 12 additions and 6 deletions

View file

@ -105,7 +105,8 @@ also <xref linkend="sec-common-options" />.</phrase></para>
<listitem><para>For the <option>--install</option>,
<option>--upgrade</option>, <option>--uninstall</option>,
<option>--switch-generation</option> and
<option>--switch-generation</option>,
<option>--delete-generations</option> and
<option>--rollback</option> operations, this flag will cause
<command>nix-env</command> to print what
<emphasis>would</emphasis> be done if this flag had not been

View file

@ -1205,10 +1205,15 @@ static void opListGenerations(Globals & globals,
}
static void deleteGeneration2(const Path & profile, unsigned int gen)
static void deleteGeneration2(Globals & globals, unsigned int gen)
{
if (globals.dryRun)
printMsg(lvlInfo, format("would remove generation %1%") % gen);
else {
printMsg(lvlInfo, format("removing generation %1%") % gen);
deleteGeneration(profile, gen);
deleteGeneration(globals.profile, gen);
}
}
@ -1229,7 +1234,7 @@ static void opDeleteGenerations(Globals & globals,
if (*i == "old") {
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j)
if (j->number != curGen)
deleteGeneration2(globals.profile, j->number);
deleteGeneration2(globals, j->number);
}
else {
@ -1239,7 +1244,7 @@ static void opDeleteGenerations(Globals & globals,
bool found = false;
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j) {
if (j->number == n) {
deleteGeneration2(globals.profile, j->number);
deleteGeneration2(globals, j->number);
found = true;
break;
}