diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-02-17T18·11+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-02-17T18·11+0000 |
commit | 46f0cb08692713954a4d452da6d7c07e17eb0cac (patch) | |
tree | c00c24bb0fa25182d96987895bf2b4c4f3040d10 /src | |
parent | 7a3e715980c3fcd84b6d12f54a18a920ebba208d (diff) |
* In "nix-env -i", print a warning if there are multiple derivations
with the same name *and* version number, and pick the first one (this means that the order in which channels appear in ~/.nix-channels matters). E.g.: $ nix-env ii aterm warning: there are multiple derivations named `aterm-2.4.2'; using the first one installing `aterm-2.4.2'
Diffstat (limited to 'src')
-rw-r--r-- | src/nix-env/main.cc | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index 985918c47094..267e478f4a9c 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -217,23 +217,6 @@ static DrvInfos filterBySelector(EvalState & state, DrvInfos elems; PathSet done; -#if 0 - /* Filter out the ones we're not interested in. */ - for (DrvInfos::const_iterator i = allElems.begin(); - i != allElems.end(); ++i) - { - DrvName drvName(i->name); - for (DrvNames::iterator j = selectors.begin(); - j != selectors.end(); ++j) - { - if (j->matches(drvName)) { - j->hits++; - elems.push_back(*i); - } - } - } -#endif - for (DrvNames::iterator i = selectors.begin(); i != selectors.end(); ++i) { @@ -248,29 +231,38 @@ static DrvInfos filterBySelector(EvalState & state, } } + /* If `newestOnly', if a selector matches multiple derivations + with the same name, pick the one with the highest version. + If there are multiple derivations with the same name *and* + version, then pick the first one. */ if (newestOnly) { /* Map from package names to derivations. */ map<string, DrvInfo> newest; + StringSet multiple; for (DrvInfos::const_iterator j = matches.begin(); j != matches.end(); ++j) { DrvName drvName(j->name); map<string, DrvInfo>::iterator k = newest.find(drvName.name); - if (k != newest.end()) - if (compareVersions(drvName.version, DrvName(k->second.name).version) > 0) - newest[drvName.name] = *j; - else - ; - else + if (k != newest.end()) { + int d = compareVersions(drvName.version, DrvName(k->second.name).version); + if (d > 0) newest[drvName.name] = *j; + else if (d == 0) multiple.insert(j->name); + } else newest[drvName.name] = *j; } matches.clear(); for (map<string, DrvInfo>::iterator j = newest.begin(); - j != newest.end(); ++j) + j != newest.end(); ++j) { + if (multiple.find(j->second.name) != multiple.end()) + printMsg(lvlInfo, + format("warning: there are multiple derivations named `%1%'; using the first one") + % j->second.name); matches.push_back(j->second); + } } /* Insert only those elements in the final list that we |