[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
39/64: nix-env: Minor change to '--delete-generations Nd' semantics
From: |
Ludovic Courtès |
Subject: |
39/64: nix-env: Minor change to '--delete-generations Nd' semantics |
Date: |
Mon, 05 Jan 2015 16:39:04 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit 700c678c2eed5e05c3e68d722c41c2b37d0a2f45
Author: Ricardo M. Correia <address@hidden>
Date: Fri Apr 11 17:10:20 2014 +0200
nix-env: Minor change to '--delete-generations Nd' semantics
The option '--delete-generations Nd' deletes all generations older than N
days. However, most likely the user does not want to delete the
generation that was active N days ago.
For example, say that you have these 3 generations:
1: <30 days ago>
2: <15 days ago>
3: <1 hour ago>
If you do --delete-generations 7d (say, as part of a cron job), most
likely you still want to keep generation 2, i.e. the generation that was
active 7 days ago (and for most of the past 7 days, in fact).
This patch fixes this issue. Note that this also affects
'nix-collect-garbage --delete-older-than Nd'.
Thanks to @roconnor for noticing the issue!
---
doc/manual/nix-collect-garbage.xml | 5 +++--
doc/manual/nix-env.xml | 3 ++-
src/nix-env/nix-env.cc | 14 ++++++++++----
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/doc/manual/nix-collect-garbage.xml
b/doc/manual/nix-collect-garbage.xml
index a97e3b7..cf87074 100644
--- a/doc/manual/nix-collect-garbage.xml
+++ b/doc/manual/nix-collect-garbage.xml
@@ -45,8 +45,9 @@ which deletes all old generations of all profiles in
impossible); and
<option>--delete-older-than</option> <replaceable>period</replaceable>,
where period is a value such as <literal>30d</literal>, which deletes
-all non-current generations that are older than the specified number of
-days in all profiles in <filename>/nix/var/nix/profiles</filename>.
+all generations older than the specified number of days in all profiles
+in <filename>/nix/var/nix/profiles</filename> (except for the generations
+that were active at that point in time).
</para>
</refsection>
diff --git a/doc/manual/nix-env.xml b/doc/manual/nix-env.xml
index 3bfcb15..c440208 100644
--- a/doc/manual/nix-env.xml
+++ b/doc/manual/nix-env.xml
@@ -1170,7 +1170,8 @@ $ nix-env --list-generations
profile. The generations can be a list of generation numbers, the
special value <literal>old</literal> to delete all non-current
generations, or a value such as <literal>30d</literal> to delete all
-non-current generations older than the specified number of days.
+generations older than the specified number of days (except for the
+generation that was active at that point in time).
Periodically deleting old generations is important to make garbage
collection effective.</para>
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 8a80526..3db84ff 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -1315,11 +1315,17 @@ static void opDeleteGenerations(Globals & globals,
oldTime = curTime - days * 24 * 3600;
- for (Generations::iterator j = gens.begin(); j != gens.end(); ++j)
{
- if (j->number == curGen) continue;
-
- if (j->creationTime < oldTime)
+ bool canDelete = false;
+ for (Generations::reverse_iterator j = gens.rbegin(); j !=
gens.rend(); ++j) {
+ if (canDelete) {
+ assert(j->creationTime < oldTime);
deleteGeneration2(globals, j->number);
+ } else if (j->creationTime < oldTime) {
+ /* We may now start deleting generations, but we don't
delete
+ this generation yet, because this generation was still
the
+ one that was active at the requested point in time. */
+ canDelete = true;
+ }
}
} else {
int n;
- 20/64: forceAttrs: Show position info, (continued)
- 20/64: forceAttrs: Show position info, Ludovic Courtès, 2015/01/05
- 22/64: derivation: Don't require certain function arguments, Ludovic Courtès, 2015/01/05
- 30/64: Update installation instructions, Ludovic Courtès, 2015/01/05
- 23/64: Show position info in string concatenation / addition errors, Ludovic Courtès, 2015/01/05
- 35/64: Don't barf when installing as root, Ludovic Courtès, 2015/01/05
- 31/64: Remove redundant stuff, Ludovic Courtès, 2015/01/05
- 24/64: Show position info in Boolean operations, Ludovic Courtès, 2015/01/05
- 38/64: Fix test evaluation, Ludovic Courtès, 2015/01/05
- 34/64: Add docbook icons to the distribution, Ludovic Courtès, 2015/01/05
- 37/64: Bump date, Ludovic Courtès, 2015/01/05
- 39/64: nix-env: Minor change to '--delete-generations Nd' semantics,
Ludovic Courtès <=
- 33/64: If a .drv cannot be parsed, show its path, Ludovic Courtès, 2015/01/05
- 40/64: trunk -> master, Ludovic Courtès, 2015/01/05
- 17/64: Pass position information to primop calls, Ludovic Courtès, 2015/01/05
- 32/64: Simplify quick start section, Ludovic Courtès, 2015/01/05
- 43/64: Set build-max-jobs to the number of available cores by default, Ludovic Courtès, 2015/01/05
- 41/64: doc fix: swap 'import' and 'export', Ludovic Courtès, 2015/01/05
- 28/64: Ensure that systemd units to into lib, not lib64, Ludovic Courtès, 2015/01/05
- 36/64: Bump version to 1.8, Ludovic Courtès, 2015/01/05
- 44/64: Install an Upstart service, Ludovic Courtès, 2015/01/05
- 45/64: Set up directories and permissions for multi-user install automatically, Ludovic Courtès, 2015/01/05