1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-08 15:13:55 +02:00

Merge pull request #5216 from kvtb/patch-2

`builtins.hashFile`, `builtins.hashString`: realize context before calculation, and discard afterwards
This commit is contained in:
Eelco Dolstra 2021-09-13 22:39:26 +02:00 committed by GitHub
commit 2e80a42c13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -937,10 +937,16 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
if (ht == htUnknown) if (ht == htUnknown)
throw Error(format("unknown hash type '%1%', at %2%") % type % pos); throw Error(format("unknown hash type '%1%', at %2%") % type % pos);
PathSet context; // discarded PathSet context;
Path p = state.coerceToPath(pos, *args[1], context); Path path = state.coerceToPath(pos, *args[1], context);
try {
state.realiseContext(context);
} catch (InvalidPathError & e) {
throw EvalError(format("cannot read '%1%', since path '%2%' is not valid, at %3%")
% 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));
} }
/* Read a directory (without . or ..) */ /* Read a directory (without . or ..) */
@ -1821,7 +1827,7 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
PathSet context; // discarded PathSet context; // discarded
string s = state.forceString(*args[1], context, pos); 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));
} }