From 429154b74c7f4b4d679ae79bbc939049f537bfaf Mon Sep 17 00:00:00 2001 From: Matthew O'Gorman Date: Wed, 6 Jan 2016 20:15:19 -0500 Subject: Implement --delete-generations + flag for keeping last N number of generations --- src/libstore/profiles.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/libstore/profiles.cc') diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc index 4a607b584506..e6300cf05552 100644 --- a/src/libstore/profiles.cc +++ b/src/libstore/profiles.cc @@ -157,6 +157,29 @@ void deleteGenerations(const Path & profile, const std::set & gens } } +void deleteGenerationsGreaterThan(const Path & profile, const string & max, bool dryRun) +{ + int max_keep = 0; + PathLocks lock; + if(max.size() < 2) + throw Error(format("invalid number of generations ‘%1%’") % max); + string str_max = string(max, 1, max.size()); + if (!string2Int(str_max, max_keep) || max_keep == 0) + throw Error(format("invalid number of generations to keep ‘%1%’") % max); + + lockProfile(lock, profile); + + int curGen; + Generations gens = findGenerations(profile, curGen); + + for (auto i = gens.rbegin(); i != gens.rend(); ++i) { + if (max_keep) { + max_keep--; + continue; + } + deleteGeneration2(profile, i->number, dryRun); + } +} void deleteOldGenerations(const Path & profile, bool dryRun) { -- cgit 1.4.1