about summary refs log tree commit diff
path: root/src/nix-env
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-02-06T16·16+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-02-06T16·16+0000
commitb8675aee5470c5387e4bfe4906e4ab1e94b610b2 (patch)
treee77860fa961a07f9303d31c977253873a98d031a /src/nix-env
parent73ab2ed4fd1c3cd974851be4f13e7a276ab16acf (diff)
* In `--list-generations', show what the current generation is.
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/main.cc8
-rw-r--r--src/nix-env/profiles.cc33
-rw-r--r--src/nix-env/profiles.hh2
3 files changed, 30 insertions, 13 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 6aa342c1daff..5ef61bb306a0 100644
--- a/src/nix-env/main.cc
+++ b/src/nix-env/main.cc
@@ -480,15 +480,17 @@ static void opListGenerations(Globals & globals,
     if (opArgs.size() != 0)
         throw UsageError(format("no arguments expected"));
 
-    Generations gens = findGenerations(globals.profile);
+    int curGen;
+    Generations gens = findGenerations(globals.profile, curGen);
 
     for (Generations::iterator i = gens.begin(); i != gens.end(); ++i) {
         tm t;
         if (!localtime_r(&i->creationTime, &t)) throw Error("cannot convert time");
-        cout << format("%|4|   %|4|-%|02|-%|02| %|02|:%|02|:%|02|\n")
+        cout << format("%|4|   %|4|-%|02|-%|02| %|02|:%|02|:%|02|   %||\n")
             % i->number
             % (t.tm_year + 1900) % (t.tm_mon + 1) % t.tm_mday
-            % t.tm_hour % t.tm_min % t.tm_sec;
+            % t.tm_hour % t.tm_min % t.tm_sec
+            % (i->number == curGen ? "(current)" : "");
     }
 }
 
diff --git a/src/nix-env/profiles.cc b/src/nix-env/profiles.cc
index 22da6336bdbf..a1e0c94a9198 100644
--- a/src/nix-env/profiles.cc
+++ b/src/nix-env/profiles.cc
@@ -11,7 +11,22 @@ static bool cmpGensByNumber(const Generation & a, const Generation & b)
 }
 
 
-Generations findGenerations(Path profile)
+/* Parse a generation name of the format
+   `<profilename>-<number>-link'. */
+static int parseName(const string & profileName, const string & name)
+{
+    if (string(name, 0, profileName.size() + 1) != profileName + "-") return -1;
+    string s = string(name, profileName.size() + 1);
+    int p = s.find("-link");
+    if (p == string::npos) return -1;
+    istringstream str(string(s, 0, p));
+    unsigned int n;
+    if (str >> n && str.eof()) return n; else return -1;
+}
+
+
+
+Generations findGenerations(Path profile, int & curGen)
 {
     Generations gens;
 
@@ -20,13 +35,8 @@ Generations findGenerations(Path profile)
     
     Strings names = readDirectory(profileDir);
     for (Strings::iterator i = names.begin(); i != names.end(); ++i) {
-        if (string(*i, 0, profileName.size() + 1) != profileName + "-") continue;
-        string s = string(*i, profileName.size() + 1);
-        int p = s.find("-link");
-        if (p == string::npos) continue;
-        istringstream str(string(s, 0, p));
-        unsigned int n;
-        if (str >> n && str.eof()) {
+        int n;
+        if ((n = parseName(profileName, *i)) != -1) {
             Generation gen;
             gen.path = profileDir + "/" + *i;
             gen.number = n;
@@ -40,6 +50,10 @@ Generations findGenerations(Path profile)
 
     gens.sort(cmpGensByNumber);
 
+    curGen = pathExists(profile)
+        ? parseName(profileName, readLink(profile))
+        : -1;
+
     return gens;
 }
 
@@ -48,7 +62,8 @@ Path createGeneration(Path profile, Path outPath, Path drvPath)
 {
     /* The new generation number should be higher than old the
        previous ones. */
-    Generations gens = findGenerations(profile);
+    int dummy;
+    Generations gens = findGenerations(profile, dummy);
     unsigned int num = gens.size() > 0 ? gens.front().number : 0;
         
     /* Create the new generation. */
diff --git a/src/nix-env/profiles.hh b/src/nix-env/profiles.hh
index f9480ed3f3d4..2422c9f7425a 100644
--- a/src/nix-env/profiles.hh
+++ b/src/nix-env/profiles.hh
@@ -18,7 +18,7 @@ typedef list<Generation> Generations;
 
 /* Returns the list of currently present generations for the specified
    profile, sorted by generation number. */
-Generations findGenerations(Path profile);
+Generations findGenerations(Path profile, int & curGen);
     
 Path createGeneration(Path profile, Path outPath, Path drvPath);