Merge pull request #5976 from edolstra/read-invalid-paths

Allow builtins.{readFile,path} on invalid paths
This commit is contained in:
Eelco Dolstra 2022-01-25 00:04:01 +01:00 committed by GitHub
commit 716a08827e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
@ -1866,10 +1870,13 @@ static void addPath(
StorePathSet refs;
if (state.store->isInStore(path)) {
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