diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-28T14·40+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-28T14·40+0000 |
commit | 151e61fa5a94950d3701f6df0b40fa970e3cf320 (patch) | |
tree | 856db2ddfb7da630682e18ee63a0004982be44ce /src/nix-env | |
parent | 4d2946c516aefd26daec8b2f4c4248e43ce85a62 (diff) |
* By default, `nix-env -i' now deletes previously installed
derivations with names matching the derivations being installed. The option `--preserve-installed / -P' overrides this behaviour.
Diffstat (limited to 'src/nix-env')
-rw-r--r-- | src/nix-env/main.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index 1f16e72ae0f1..09604a2d0d20 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -17,6 +17,7 @@ struct Globals Path nixExprPath; EvalState state; bool dryRun; + bool preserveInstalled; }; @@ -225,7 +226,7 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs, static void installDerivations(EvalState & state, Path nePath, DrvNames & selectors, const Path & profile, - bool dryRun) + bool dryRun, bool preserveInstalled) { debug(format("installing derivations from `%1%'") % nePath); @@ -235,6 +236,7 @@ static void installDerivations(EvalState & state, /* Filter out the ones we're not interested in. */ DrvInfos selectedDrvs; + StringSet selectedNames; for (DrvInfos::iterator i = availDrvs.begin(); i != availDrvs.end(); ++i) { @@ -247,6 +249,7 @@ static void installDerivations(EvalState & state, format("installing `%1%'") % i->second.name); j->hits++; selectedDrvs.insert(*i); + selectedNames.insert(drvName.name); } } } @@ -261,7 +264,18 @@ static void installDerivations(EvalState & state, /* Add in the already installed derivations. */ DrvInfos installedDrvs; queryInstalled(state, installedDrvs, profile); - selectedDrvs.insert(installedDrvs.begin(), installedDrvs.end()); + + for (DrvInfos::iterator i = installedDrvs.begin(); + i != installedDrvs.end(); ++i) + { + DrvName drvName(i->second.name); + if (!preserveInstalled && + selectedNames.find(drvName.name) != selectedNames.end()) + printMsg(lvlInfo, + format("uninstalling `%1%'") % i->second.name); + else + selectedDrvs.insert(*i); + } if (dryRun) return; @@ -278,7 +292,8 @@ static void opInstall(Globals & globals, DrvNames drvNames = drvNamesFromArgs(opArgs); installDerivations(globals.state, globals.nixExprPath, - drvNames, globals.profile, globals.dryRun); + drvNames, globals.profile, globals.dryRun, + globals.preserveInstalled); } @@ -641,6 +656,7 @@ void run(Strings args) Globals globals; globals.nixExprPath = getDefNixExprPath(); globals.dryRun = false; + globals.preserveInstalled = false; for (Strings::iterator i = args.begin(); i != args.end(); ++i) { string arg = *i; @@ -681,6 +697,8 @@ void run(Strings args) printMsg(lvlInfo, "(dry run; not doing anything)"); globals.dryRun = true; } + else if (arg == "--preserve-installed" || arg == "-P") + globals.preserveInstalled = true; else if (arg[0] == '-') opFlags.push_back(arg); else |