From 3d8318870289d7b6b08677fcd2da6ceb0b082f8c Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Mon, 18 May 2015 08:38:49 +0200 Subject: Enable lazy/sparse allocation of generation symlinks: avoid creating new generations if a generation already exists. Alternatively or additionally I propose a mode where only the *last* generation will be sparse. --- src/nix-env/profiles.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/nix-env') diff --git a/src/nix-env/profiles.cc b/src/nix-env/profiles.cc index d8eb0ef5269c..1691dc099f4c 100644 --- a/src/nix-env/profiles.cc +++ b/src/nix-env/profiles.cc @@ -80,7 +80,22 @@ Path createGeneration(Path profile, Path outPath) previous ones. */ int dummy; Generations gens = findGenerations(profile, dummy); - unsigned int num = gens.size() > 0 ? gens.back().number : 0; + + unsigned int num; + if (gens.size() > 0) { + /* Check existing generations whether they represent an + environment we already materialized before. In that case: + avoid cluttering the system with additional symlinks. */ + for (auto & gen : gens) { + if (readLink(gen.path) == outPath) { + return gen.path; + } + } + + num = gens.back().number; + } else { + num = 0; + } /* Create the new generation. Note that addPermRoot() blocks if the garbage collector is running to prevent the stuff we've -- cgit 1.4.1