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 --- doc/manual/command-ref/nix-env.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/manual/command-ref/nix-env.xml b/doc/manual/command-ref/nix-env.xml index d4563ac47551..f0e70a41c024 100644 --- a/doc/manual/command-ref/nix-env.xml +++ b/doc/manual/command-ref/nix-env.xml @@ -1346,9 +1346,10 @@ $ nix-env --list-generations This operation deletes the specified generations of the current profile. The generations can be a list of generation numbers, the special value old to delete all non-current -generations, or a value such as 30d to delete all +generations, a value such as 30d to delete all generations older than the specified number of days (except for the -generation that was active at that point in time). +generation that was active at that point in time), or a value such as. ++5 to delete all but the number of items specified. Periodically deleting old generations is important to make garbage collection effective. @@ -1359,6 +1360,8 @@ collection effective. $ nix-env --delete-generations 3 4 8 +$ nix-env --delete-generations +5 + $ nix-env --delete-generations 30d $ nix-env -p other_profile --delete-generations old -- cgit 1.4.1 From 467fdd8ca4d63972dbd94f0496918522c58916a0 Mon Sep 17 00:00:00 2001 From: Matthew O'Gorman Date: Thu, 1 Mar 2018 22:59:00 -0500 Subject: only delete things older than current gen and update logic in doc as well --- doc/manual/command-ref/nix-env.xml | 10 +++++----- src/libstore/profiles.cc | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/manual/command-ref/nix-env.xml b/doc/manual/command-ref/nix-env.xml index f0e70a41c024..7eb9cc855bae 100644 --- a/doc/manual/command-ref/nix-env.xml +++ b/doc/manual/command-ref/nix-env.xml @@ -1349,9 +1349,9 @@ special value old to delete all non-current generations, a value such as 30d to delete all generations older than the specified number of days (except for the generation that was active at that point in time), or a value such as. -+5 to delete all but the number of items specified. -Periodically deleting old generations is important to make garbage -collection effective. ++5 to only keep the specified items older than the +current generation. Periodically deleting old generations is important +to make garbage collection effective. @@ -1461,7 +1461,7 @@ error: no generation older than the current (91) exists Environment variables - + NIX_PROFILE Location of the Nix profile. Defaults to the @@ -1475,6 +1475,6 @@ error: no generation older than the current (91) exists - + 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 & 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); + } } } -- cgit 1.4.1