From 9fd9dedf12bb64e02b35e9231173f9ebae5e1492 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 13 Sep 2012 18:05:04 -0400 Subject: [PATCH] nix-env --delete-generations: Support --dry-run flag Fixes #43. --- doc/manual/nix-env.xml | 3 ++- src/nix-env/nix-env.cc | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/manual/nix-env.xml b/doc/manual/nix-env.xml index 02a51c6e9..a5217450b 100644 --- a/doc/manual/nix-env.xml +++ b/doc/manual/nix-env.xml @@ -105,7 +105,8 @@ also . For the , , , - and + , + and operations, this flag will cause nix-env to print what would be done if this flag had not been diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 5174daf90..dd2fa3048 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -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) { - printMsg(lvlInfo, format("removing generation %1%") % gen); - deleteGeneration(profile, gen); + if (globals.dryRun) + printMsg(lvlInfo, format("would remove generation %1%") % gen); + else { + printMsg(lvlInfo, format("removing generation %1%") % 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; }