mirror of
https://github.com/NixOS/nix
synced 2025-06-27 12:41:15 +02:00
Merge pull request #767 from mogorman/garbage_collect_keep_last_few
Implement --delete-generations + flag for keeping last N number of gens
This commit is contained in:
commit
93aa3bea2e
4 changed files with 42 additions and 6 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue