aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/local-derivation-goal.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-05-10 10:41:59 -0400
committerGitHub <noreply@github.com>2023-05-10 10:41:59 -0400
commit53a1354acfa9a3d7e0a6c3914ff3c53115d4c452 (patch)
tree650fc498d41d3e6393b09eef60640e0996f420ad /src/libstore/build/local-derivation-goal.cc
parent85ff21205104a475c8745c5919aa1378dd49ecad (diff)
parent6a3a87a714e1f3be1464f8fd4c82714b7d032879 (diff)
Merge pull request #3959 from obsidiansystems/ca-drv-exotic
Derivations can output "text-hashed" data
Diffstat (limited to 'src/libstore/build/local-derivation-goal.cc')
-rw-r--r--src/libstore/build/local-derivation-goal.cc60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index 2f545627b..e6db298d6 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -2426,37 +2426,51 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
throw BuildError(
"output path %1% without valid stats info",
actualPath);
- if (outputHash.method == FileIngestionMethod::Flat) {
+ if (outputHash.method == ContentAddressMethod { FileIngestionMethod::Flat } ||
+ outputHash.method == ContentAddressMethod { TextIngestionMethod {} })
+ {
/* 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(
"output path '%1%' should be a non-executable regular file "
- "since recursive hashing is not enabled (outputHashMode=flat)",
+ "since recursive hashing is not enabled (one of outputHashMode={flat,text} is true)",
actualPath);
}
rewriteOutput();
/* FIXME optimize and deduplicate with addToStore */
std::string oldHashPart { scratchPath->hashPart() };
HashModuloSink caSink { outputHash.hashType, oldHashPart };
- switch (outputHash.method) {
- case FileIngestionMethod::Recursive:
- dumpPath(actualPath, caSink);
- break;
- case FileIngestionMethod::Flat:
- readFile(actualPath, caSink);
- break;
- }
+ std::visit(overloaded {
+ [&](const TextIngestionMethod &) {
+ readFile(actualPath, caSink);
+ },
+ [&](const FileIngestionMethod & m2) {
+ switch (m2) {
+ case FileIngestionMethod::Recursive:
+ dumpPath(actualPath, caSink);
+ break;
+ case FileIngestionMethod::Flat:
+ readFile(actualPath, caSink);
+ break;
+ }
+ },
+ }, outputHash.method.raw);
auto got = caSink.finish().first;
+
+ auto optCA = ContentAddressWithReferences::fromPartsOpt(
+ outputHash.method,
+ std::move(got),
+ rewriteRefs());
+ if (!optCA) {
+ // TODO track distinct failure modes separately (at the time of
+ // writing there is just one but `nullopt` is unclear) so this
+ // message can't get out of sync.
+ throw BuildError("output path '%s' has illegal content address, probably a spurious self-reference with text hashing");
+ }
ValidPathInfo newInfo0 {
worker.store,
outputPathName(drv->name, outputName),
- FixedOutputInfo {
- .hash = {
- .method = outputHash.method,
- .hash = got,
- },
- .references = rewriteRefs(),
- },
+ *std::move(optCA),
Hash::dummy,
};
if (*scratchPath != newInfo0.path) {
@@ -2503,13 +2517,14 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
},
[&](const DerivationOutput::CAFixed & dof) {
+ auto wanted = dof.ca.getHash();
+
auto newInfo0 = newInfoFromCA(DerivationOutput::CAFloating {
- .method = dof.hash.method,
- .hashType = dof.hash.hash.type,
+ .method = dof.ca.getMethod(),
+ .hashType = wanted.type,
});
/* Check wanted hash */
- const Hash & wanted = dof.hash.hash;
assert(newInfo0.ca);
auto got = newInfo0.ca->getHash();
if (wanted != got) {
@@ -2522,6 +2537,11 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
wanted.to_string(SRI, true),
got.to_string(SRI, true)));
}
+ if (!newInfo0.references.empty())
+ delayedException = std::make_exception_ptr(
+ BuildError("illegal path references in fixed-output derivation '%s'",
+ worker.store.printStorePath(drvPath)));
+
return newInfo0;
},