Skip to content

Commit

Permalink
Revert "Don't anticipate CA but not fixed outputs for now"
Browse files Browse the repository at this point in the history
This reverts commit 3a9e4c3.
  • Loading branch information
meditans committed Jul 17, 2020
1 parent 205dcd1 commit bbc633c
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3721,9 +3721,22 @@ void DerivationGoal::registerOutputs()
hash). */
std::optional<ContentAddress> ca;

if (derivationIsFixed(derivationType)) {

FixedOutputHash outputHash = std::get<DerivationOutputFixed>(i.second.output).hash;
if (! std::holds_alternative<DerivationOutputInputAddressed>(i.second.output)) {
DerivationOutputFloating outputHash;
std::visit(overloaded {
[&](DerivationOutputInputAddressed doi) {
throw Error("No.");
},
[&](DerivationOutputFixed dof) {
outputHash = DerivationOutputFloating {
.method = dof.hash.method,
.hashType = *dof.hash.hash.type,
};
},
[&](DerivationOutputFloating dof) {
outputHash = dof;
},
}, i.second.output);

if (outputHash.method == FileIngestionMethod::Flat) {
/* The output path should be a regular file without execute permission. */
Expand All @@ -3737,22 +3750,33 @@ void DerivationGoal::registerOutputs()
/* Check the hash. In hash mode, move the path produced by
the derivation to its content-addressed location. */
Hash h2 = outputHash.method == FileIngestionMethod::Recursive
? hashPath(*outputHash.hash.type, actualPath).first
: hashFile(*outputHash.hash.type, actualPath);
? hashPath(outputHash.hashType, actualPath).first
: hashFile(outputHash.hashType, actualPath);

auto dest = worker.store.makeFixedOutputPath(outputHash.method, h2, i.second.path(worker.store, drv->name).name());

if (outputHash.hash != h2) {
// true if either floating CA, or incorrect fixed hash.
bool needsMove = true;

if (auto p = std::get_if<DerivationOutputFixed>(& i.second.output)) {
Hash & h = p->hash.hash;
if (h != 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),
outputHash.hash.to_string(SRI, true),
h.to_string(SRI, true),
h2.to_string(SRI, true)));
} else {
// matched the fixed hash, so no move needed.
needsMove = false;
}
}

if (needsMove) {
Path actualDest = worker.store.Store::toRealPath(dest);

if (worker.store.isValidPath(dest))
Expand Down

0 comments on commit bbc633c

Please sign in to comment.