nix-env --set-flag: Barf if a selector doesn't match any installed package

Fixes #184.
This commit is contained in:
Eelco Dolstra 2013-12-20 13:56:42 +01:00
parent 194e3374b8
commit 7d203faff6

View file

@ -233,6 +233,15 @@ static bool isPrebuilt(EvalState & state, DrvInfo & elem)
} }
static void checkSelectorUse(DrvNames & selectors)
{
/* Check that all selectors have been used. */
foreach (DrvNames::iterator, i, selectors)
if (i->hits == 0 && i->fullName != "*")
throw Error(format("selector `%1%' matches no derivations") % i->fullName);
}
static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems, static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems,
const Strings & args, bool newestOnly) const Strings & args, bool newestOnly)
{ {
@ -315,11 +324,7 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems,
} }
} }
/* Check that all selectors have been used. */ checkSelectorUse(selectors);
foreach (DrvNames::iterator, i, selectors)
if (i->hits == 0 && i->fullName != "*")
throw Error(format("selector `%1%' matches no derivations")
% i->fullName);
return elems; return elems;
} }
@ -673,11 +678,14 @@ static void opSetFlag(Globals & globals,
foreach (DrvNames::iterator, j, selectors) foreach (DrvNames::iterator, j, selectors)
if (j->matches(drvName)) { if (j->matches(drvName)) {
printMsg(lvlInfo, format("setting flag on `%1%'") % i->name); printMsg(lvlInfo, format("setting flag on `%1%'") % i->name);
j->hits++;
setMetaFlag(globals.state, *i, flagName, flagValue); setMetaFlag(globals.state, *i, flagName, flagValue);
break; break;
} }
} }
checkSelectorUse(selectors);
/* Write the new user environment. */ /* Write the new user environment. */
if (createUserEnv(globals.state, installedElems, if (createUserEnv(globals.state, installedElems,
globals.profile, settings.envKeepDerivations, lockToken)) break; globals.profile, settings.envKeepDerivations, lockToken)) break;