about summary refs log tree commit diff
path: root/src/nix-env/profiles.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-02-06T16·03+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-02-06T16·03+0000
commit73ab2ed4fd1c3cd974851be4f13e7a276ab16acf (patch)
tree3ad2775595b995f94c19ac54b3ab70cbf86e8cfe /src/nix-env/profiles.cc
parent7c0fa4474f0010f8266b85e891ca6049595ecb32 (diff)
* A command `--list-generations' to show all generations for a
  profile.

Diffstat (limited to 'src/nix-env/profiles.cc')
-rw-r--r--src/nix-env/profiles.cc41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/nix-env/profiles.cc b/src/nix-env/profiles.cc
index 5b9c004066b5..22da6336bdbf 100644
--- a/src/nix-env/profiles.cc
+++ b/src/nix-env/profiles.cc
@@ -1,13 +1,23 @@
 #include "profiles.hh"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
-Path createGeneration(Path profile, Path outPath, Path drvPath)
+
+static bool cmpGensByNumber(const Generation & a, const Generation & b)
 {
+    return a.number < b.number;
+}
+
+
+Generations findGenerations(Path profile)
+{
+    Generations gens;
+
     Path profileDir = dirOf(profile);
     string profileName = baseNameOf(profile);
     
-    unsigned int num = 0;
-    
     Strings names = readDirectory(profileDir);
     for (Strings::iterator i = names.begin(); i != names.end(); ++i) {
         if (string(*i, 0, profileName.size() + 1) != profileName + "-") continue;
@@ -16,9 +26,32 @@ Path createGeneration(Path profile, Path outPath, Path drvPath)
         if (p == string::npos) continue;
         istringstream str(string(s, 0, p));
         unsigned int n;
-        if (str >> n && str.eof() && n >= num) num = n + 1;
+        if (str >> n && str.eof()) {
+            Generation gen;
+            gen.path = profileDir + "/" + *i;
+            gen.number = n;
+            struct stat st;
+            if (lstat(gen.path.c_str(), &st) != 0)
+                throw SysError(format("statting `%1%'") % gen.path);
+            gen.creationTime = st.st_mtime;
+            gens.push_back(gen);
+        }
     }
 
+    gens.sort(cmpGensByNumber);
+
+    return gens;
+}
+
+
+Path createGeneration(Path profile, Path outPath, Path drvPath)
+{
+    /* The new generation number should be higher than old the
+       previous ones. */
+    Generations gens = findGenerations(profile);
+    unsigned int num = gens.size() > 0 ? gens.front().number : 0;
+        
+    /* Create the new generation. */
     Path generation, gcrootSrc;
 
     while (1) {