Skip to content

Commit

Permalink
Allow builtins.{readFile,path} on invalid paths
Browse files Browse the repository at this point in the history
Stop-gap measure to fix NixOS#5975.
  • Loading branch information
edolstra committed Jan 24, 2022
1 parent e66550c commit 8cbbaf2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,13 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
string s = readFile(path);
if (s.find((char) 0) != string::npos)
throw Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
auto refs = state.store->isInStore(path) ?
state.store->queryPathInfo(state.store->toStorePath(path).first)->references :
StorePathSet{};
StorePathSet refs;
if (state.store->isInStore(path)) {
try {
refs = state.store->queryPathInfo(state.store->toStorePath(path).first)->references;
} catch (Error &) { // FIXME: should be InvalidPathError
}
}
auto context = state.store->printStorePathSet(refs);
v.mkString(s, context);
}
Expand Down Expand Up @@ -1866,10 +1870,13 @@ static void addPath(
StorePathSet refs;

if (state.store->isInStore(path)) {
auto [storePath, subPath] = state.store->toStorePath(path);
// FIXME: we should scanForReferences on the path before adding it
refs = state.store->queryPathInfo(storePath)->references;
path = state.store->toRealPath(storePath) + subPath;
try {
auto [storePath, subPath] = state.store->toStorePath(path);
// FIXME: we should scanForReferences on the path before adding it
refs = state.store->queryPathInfo(storePath)->references;
path = state.store->toRealPath(storePath) + subPath;
} catch (Error &) { // FIXME: should be InvalidPathError
}
}

path = evalSettings.pureEval && expectedHash
Expand Down

0 comments on commit 8cbbaf2

Please sign in to comment.