aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-01-25 00:04:01 +0100
committerGitHub <noreply@github.com>2022-01-25 00:04:01 +0100
commit716a08827e6646ae2e9c7940b3c9090d806ae400 (patch)
tree4404dcab4ecf5d29a25a0a3d490c8b178b3d0cd1 /src
parente66550c917cc60113fa10db66b7b751ffe399214 (diff)
parent8cbbaf23e889270867420431f0ab6c0ffa722335 (diff)
Merge pull request #5976 from edolstra/read-invalid-paths
Allow builtins.{readFile,path} on invalid paths
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/primops.cc21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 074181e13..9d36f72a8 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -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)) {
- 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