aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-11-04 14:19:31 +0100
committerNaïm Favier <n@monade.li>2022-11-11 13:04:34 +0100
commite7ed9ae0c711c4efd83756b16379549ecff52355 (patch)
tree54d3b927057e87184387dfe49333ce9c5db61682 /src/libexpr/primops.cc
parentac0fb38e8a5a25a84fa17704bd31b453211263eb (diff)
Restrict `readFile` context to references that appear in the string
When calling `builtins.readFile` on a store path, the references of that path are currently added to the resulting string's context. This change makes those references the *possible* context of the string, but filters them to keep only the references whose hash actually appears in the string, similarly to what is done for determining the runtime references of a path.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 28b998474..ff620ca63 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -5,6 +5,7 @@
#include "globals.hh"
#include "json-to-value.hh"
#include "names.hh"
+#include "references.hh"
#include "store-api.hh"
#include "util.hh"
#include "json.hh"
@@ -1542,6 +1543,10 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, V
refs = state.store->queryPathInfo(state.store->toStorePath(path).first)->references;
} catch (Error &) { // FIXME: should be InvalidPathError
}
+ // Re-scan references to filter down to just the ones that actually occur in the file.
+ auto refsSink = PathRefScanSink::fromPaths(refs);
+ refsSink << s;
+ refs = refsSink.getResultPaths();
}
auto context = state.store->printStorePathSet(refs);
v.mkString(s, context);