1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-08 06:53:54 +02:00

hashFile, hashString: realize context before calculation, and discard afterwards

This commit is contained in:
kvtb 2021-09-05 14:42:06 +00:00 committed by GitHub
parent 896fad9119
commit 2b665a311e
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));
} }