1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 04:01:47 +02:00

Store parsed hashes in DerivationOutput

It's best to detect invalid data as soon as possible, with data types
that make storing it impossible.
This commit is contained in:
John Ericson 2020-03-22 23:43:07 -04:00
parent f5494d9442
commit 832bd534dc
8 changed files with 128 additions and 63 deletions

View file

@ -3647,10 +3647,7 @@ void DerivationGoal::registerOutputs()
if (fixedOutput) {
FileIngestionMethod recursive; Hash h;
i.second.parseHashInfo(recursive, h);
if (!static_cast<bool>(recursive)) {
if (i.second.hash->method == FileIngestionMethod::Flat) {
/* The output path should be a regular file without execute permission. */
if (!S_ISREG(st.st_mode) || (st.st_mode & S_IXUSR) != 0)
throw BuildError(
@ -3659,18 +3656,22 @@ void DerivationGoal::registerOutputs()
/* Check the hash. In hash mode, move the path produced by
the derivation to its content-addressed location. */
Hash h2 = static_cast<bool>(recursive) ? hashPath(h.type, actualPath).first : hashFile(h.type, actualPath);
Hash h2 = i.second.hash->method == FileIngestionMethod::Recursive
? hashPath(i.second.hash->hash.type, actualPath).first
: hashFile(i.second.hash->hash.type, actualPath);
auto dest = worker.store.makeFixedOutputPath(recursive, h2, i.second.path.name());
auto dest = worker.store.makeFixedOutputPath(i.second.hash->method, h2, i.second.path.name());
if (h != h2) {
if (i.second.hash->hash != h2) {
/* Throw an error after registering the path as
valid. */
worker.hashMismatch = true;
delayedException = std::make_exception_ptr(
BuildError("hash mismatch in fixed-output derivation '%s':\n wanted: %s\n got: %s",
worker.store.printStorePath(dest), h.to_string(SRI), h2.to_string(SRI)));
worker.store.printStorePath(dest),
i.second.hash->hash.to_string(SRI),
h2.to_string(SRI)));
Path actualDest = worker.store.Store::toRealPath(dest);
@ -3690,7 +3691,7 @@ void DerivationGoal::registerOutputs()
else
assert(worker.store.parseStorePath(path) == dest);
ca = makeFixedOutputCA(recursive, h2);
ca = makeFixedOutputCA(i.second.hash->method, h2);
}
/* Get rid of all weird permissions. This also checks that