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:
commit
2e80a42c13
1 changed files with 10 additions and 4 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue