From 73ab2ed4fd1c3cd974851be4f13e7a276ab16acf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 6 Feb 2004 16:03:27 +0000 Subject: * A command `--list-generations' to show all generations for a profile. --- src/nix-env/profiles.cc | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/nix-env/profiles.cc') diff --git a/src/nix-env/profiles.cc b/src/nix-env/profiles.cc index 5b9c004066..22da6336bd 100644 --- a/src/nix-env/profiles.cc +++ b/src/nix-env/profiles.cc @@ -1,13 +1,23 @@ #include "profiles.hh" +#include +#include +#include -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) { -- cgit 1.4.1