about summary refs log tree commit diff
path: root/src/nix-env
diff options
context:
space:
mode:
authorRicardo M. Correia <rcorreia@wizy.org>2014-03-11T20·47+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-03-29T23·54+0100
commit7ef7597f71b282265a9f79afe4608cd3b1bc4127 (patch)
tree76358e2bb987f7ca996b4330e9895eeed9053994 /src/nix-env
parent59c90196850b6ac8c110e54c7f03d6417ed9bf61 (diff)
nix-env: Add support for --delete-generations 15d
It will delete all generations older than the specified number of days.
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/nix-env.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 333a7fe8c0ca..8a805263477a 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -1304,9 +1304,24 @@ static void opDeleteGenerations(Globals & globals,
             for (Generations::iterator j = gens.begin(); j != gens.end(); ++j)
                 if (j->number != curGen)
                     deleteGeneration2(globals, j->number);
-        }
+        } else if (i->size() >= 2 && tolower(*i->rbegin()) == 'd') {
+            time_t curTime = time(NULL);
+            time_t oldTime;
+            string strDays = string(*i, 0, i->size() - 1);
+            int days;
 
-        else {
+            if (!string2Int(strDays, days) || days < 1)
+                throw UsageError(format("invalid number of days specifier `%1%'") % *i);
+
+            oldTime = curTime - days * 24 * 3600;
+
+            for (Generations::iterator j = gens.begin(); j != gens.end(); ++j) {
+                if (j->number == curGen) continue;
+
+                if (j->creationTime < oldTime)
+                    deleteGeneration2(globals, j->number);
+            }
+        } else {
             int n;
             if (!string2Int(*i, n) || n < 0)
                 throw UsageError(format("invalid generation specifier `%1%'")  % *i);