aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkvtb <76634406+kvtb@users.noreply.github.com>2021-09-05 14:42:06 +0000
committerEelco Dolstra <edolstra@gmail.com>2021-09-13 22:34:58 +0200
commitc6fa7775de413a799b9a137dceced5dcf0f5e6ed (patch)
tree275b23eb840d20a0e9145f7fe584cb753c3f5967
parentb55daf850a93b7cb2c6777c8920b4f2065eca705 (diff)
hashFile, hashString: realize context before calculation, and discard afterwards
-rw-r--r--src/libexpr/primops.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 25d60e175..8a087a781 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1492,15 +1492,20 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
string type = state.forceStringNoCtx(*args[0], pos);
std::optional<HashType> ht = parseHashType(type);
if (!ht)
- throw Error({
- .msg = hintfmt("unknown hash type '%1%'", type),
- .errPos = pos
- });
+ throw Error({
+ .msg = hintfmt("unknown hash type '%1%'", type),
+ .errPos = pos
+ });
- PathSet context; // discarded
- Path p = state.coerceToPath(pos, *args[1], context);
+ PathSet context;
+ Path path = state.coerceToPath(pos, *args[1], context);
+ try {
+ state.realiseContext(context);
+ } catch (InvalidPathError & e) {
+ throw EvalError("cannot read '%s' since path '%s' is not valid, at %s", path, e.path, pos);
+ }
- mkString(v, hashFile(*ht, state.checkSourcePath(p)).to_string(Base16, false), context);
+ mkString(v, hashFile(*ht, state.checkSourcePath(state.toRealPath(path, context))).to_string(Base16, false));
}
static RegisterPrimOp primop_hashFile({
@@ -3193,7 +3198,7 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
PathSet context; // discarded
string s = state.forceString(*args[1], context, pos);
- mkString(v, hashString(*ht, s).to_string(Base16, false), context);
+ mkString(v, hashString(*ht, s).to_string(Base16, false));
}
static RegisterPrimOp primop_hashString({