aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
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/libstore
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/libstore')
-rw-r--r--src/libstore/profiles.cc23
-rw-r--r--src/libstore/profiles.hh2
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc
index 4a607b584..4c6af567a 100644
--- a/src/libstore/profiles.cc
+++ b/src/libstore/profiles.cc
@@ -157,6 +157,29 @@ void deleteGenerations(const Path & profile, const std::set<unsigned int> & gens
}
}
+void deleteGenerationsGreaterThan(const Path & profile, int max, bool dryRun)
+{
+ PathLocks lock;
+ lockProfile(lock, profile);
+
+ int curGen;
+ bool fromCurGen = false;
+ Generations gens = findGenerations(profile, curGen);
+ for (auto i = gens.rbegin(); i != gens.rend(); ++i) {
+ if (i->number == curGen) {
+ fromCurGen = true;
+ max--;
+ continue;
+ }
+ if (fromCurGen) {
+ if (max) {
+ max--;
+ continue;
+ }
+ deleteGeneration2(profile, i->number, dryRun);
+ }
+ }
+}
void deleteOldGenerations(const Path & profile, bool dryRun)
{
diff --git a/src/libstore/profiles.hh b/src/libstore/profiles.hh
index 1d4e6d303..5fa1533de 100644
--- a/src/libstore/profiles.hh
+++ b/src/libstore/profiles.hh
@@ -39,6 +39,8 @@ void deleteGeneration(const Path & profile, unsigned int gen);
void deleteGenerations(const Path & profile, const std::set<unsigned int> & gensToDelete, bool dryRun);
+void deleteGenerationsGreaterThan(const Path & profile, const int max, bool dryRun);
+
void deleteOldGenerations(const Path & profile, bool dryRun);
void deleteGenerationsOlderThan(const Path & profile, time_t t, bool dryRun);