From d62fc71b851295b4c5692ec5fa362a06172e66ae Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 3 Dec 2012 21:01:41 +0100 Subject: Fix the ‘--prebuilt-only’ flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nix-env/nix-env.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/nix-env/nix-env.cc') diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index dda725606560..b57e54c758f6 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -212,14 +212,14 @@ static int comparePriorities(EvalState & state, } +// FIXME: this function is rather slow since it checks a single path +// at a time. static bool isPrebuilt(EvalState & state, const DrvInfo & elem) { - assert(false); -#if 0 - return - store->isValidPath(elem.queryOutPath(state)) || - store->hasSubstitutes(elem.queryOutPath(state)); -#endif + Path path = elem.queryOutPath(state); + if (store->isValidPath(path)) return true; + PathSet ps = store->querySubstitutablePaths(singleton(path)); + return ps.find(path) != ps.end(); } @@ -938,7 +938,7 @@ static void opQuery(Globals & globals, /* Query which paths have substitutes. */ PathSet validPaths, substitutablePaths; - if (printStatus) { + if (printStatus || globals.prebuiltOnly) { PathSet paths; foreach (vector::iterator, i, elems2) try { @@ -964,7 +964,10 @@ static void opQuery(Globals & globals, startNest(nest, lvlDebug, format("outputting query result `%1%'") % i->attrPath); - if (globals.prebuiltOnly && !isPrebuilt(globals.state, *i)) continue; + if (globals.prebuiltOnly && + validPaths.find(i->queryOutPath(globals.state)) == validPaths.end() && + substitutablePaths.find(i->queryOutPath(globals.state)) == substitutablePaths.end()) + continue; /* For table output. */ Strings columns; -- cgit 1.4.1