aboutsummaryrefslogtreecommitdiff
path: root/src/nix-env
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2018-05-31 10:00:21 +0200
committerGitHub <noreply@github.com>2018-05-31 10:00:21 +0200
commit93aa3bea2e8e2082dd3a07e5d4a7771bd9df52c0 (patch)
tree15c131faab413479fb118a34e12b14520b664d98 /src/nix-env
parentbbbfc180d9024991b9879e6d3c3c91d078bb499a (diff)
parent467fdd8ca4d63972dbd94f0496918522c58916a0 (diff)
Merge pull request #767 from mogorman/garbage_collect_keep_last_few
Implement --delete-generations + flag for keeping last N number of gens
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/nix-env.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index f60ff9e07..a43b103f6 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -1284,6 +1284,14 @@ static void opDeleteGenerations(Globals & globals, Strings opFlags, Strings opAr
deleteOldGenerations(globals.profile, globals.dryRun);
} else if (opArgs.size() == 1 && opArgs.front().find('d') != string::npos) {
deleteGenerationsOlderThan(globals.profile, opArgs.front(), globals.dryRun);
+ } else if (opArgs.size() == 1 && opArgs.front().find('+') != string::npos) {
+ if(opArgs.front().size() < 2)
+ throw Error(format("invalid number of generations ‘%1%’") % opArgs.front());
+ string str_max = string(opArgs.front(), 1, opArgs.front().size());
+ int max;
+ if (!string2Int(str_max, max) || max == 0)
+ throw Error(format("invalid number of generations to keep ‘%1%’") % opArgs.front());
+ deleteGenerationsGreaterThan(globals.profile, max, globals.dryRun);
} else {
std::set<unsigned int> gens;
for (auto & i : opArgs) {