about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/profiles.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc
index b43ec66f60c7..4c6af567ae6f 100644
--- a/src/libstore/profiles.cc
+++ b/src/libstore/profiles.cc
@@ -160,19 +160,24 @@ 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 (max) {
+        if (i->number == curGen) {
+            fromCurGen = true;
             max--;
             continue;
         }
-        if (i->number != curGen)
+        if (fromCurGen) {
+            if (max) {
+                max--;
+                continue;
+            }
             deleteGeneration2(profile, i->number, dryRun);
+        }
     }
 }