aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/derivations.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-07-05 18:53:44 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-07-07 07:30:01 -0400
commit903700c5e168e2ab5bd6bee5e09b5908cb2908d6 (patch)
treea9b92b2a5e04cfae03a02b5d92aaa2719d8d30b8 /src/libstore/derivations.cc
parent6db66ebfc55769edd0c6bc70fcbd76246d4d26e0 (diff)
Simplify `ContentAddress`
Whereas `ContentAddressWithReferences` is a sum type complex because different varieties support different notions of reference, and `ContentAddressMethod` is a nested enum to support that, `ContentAddress` can be a simple pair of a method and hash. `ContentAddress` does not need to be a sum type on the outside because the choice of method doesn't effect what type of hashes we can use. Co-Authored-By: Cale Gibbard <cgibbard@gmail.com>
Diffstat (limited to 'src/libstore/derivations.cc')
-rw-r--r--src/libstore/derivations.cc22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 6f63685d4..b831b2fe5 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -232,9 +232,10 @@ static DerivationOutput parseDerivationOutput(const Store & store,
validatePath(pathS);
auto hash = Hash::parseNonSRIUnprefixed(hashS, hashType);
return DerivationOutput::CAFixed {
- .ca = ContentAddress::fromParts(
- std::move(method),
- std::move(hash)),
+ .ca = ContentAddress {
+ .method = std::move(method),
+ .hash = std::move(hash),
+ },
};
} else {
experimentalFeatureSettings.require(Xp::CaDerivations);
@@ -395,7 +396,7 @@ std::string Derivation::unparse(const Store & store, bool maskOutputs,
[&](const DerivationOutput::CAFixed & dof) {
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(dof.path(store, name, i.first)));
s += ','; printUnquotedString(s, dof.ca.printMethodAlgo());
- s += ','; printUnquotedString(s, dof.ca.getHash().to_string(Base16, false));
+ s += ','; printUnquotedString(s, dof.ca.hash.to_string(Base16, false));
},
[&](const DerivationOutput::CAFloating & dof) {
s += ','; printUnquotedString(s, "");
@@ -628,7 +629,7 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut
auto & dof = std::get<DerivationOutput::CAFixed>(i.second.raw());
auto hash = hashString(htSHA256, "fixed:out:"
+ dof.ca.printMethodAlgo() + ":"
- + dof.ca.getHash().to_string(Base16, false) + ":"
+ + dof.ca.hash.to_string(Base16, false) + ":"
+ store.printStorePath(dof.path(store, drv.name, i.first)));
outputHashes.insert_or_assign(i.first, std::move(hash));
}
@@ -780,7 +781,7 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr
[&](const DerivationOutput::CAFixed & dof) {
out << store.printStorePath(dof.path(store, drv.name, i.first))
<< dof.ca.printMethodAlgo()
- << dof.ca.getHash().to_string(Base16, false);
+ << dof.ca.hash.to_string(Base16, false);
},
[&](const DerivationOutput::CAFloating & dof) {
out << ""
@@ -970,7 +971,7 @@ nlohmann::json DerivationOutput::toJSON(
[&](const DerivationOutput::CAFixed & dof) {
res["path"] = store.printStorePath(dof.path(store, drvName, outputName));
res["hashAlgo"] = dof.ca.printMethodAlgo();
- res["hash"] = dof.ca.getHash().to_string(Base16, false);
+ res["hash"] = dof.ca.hash.to_string(Base16, false);
// FIXME print refs?
},
[&](const DerivationOutput::CAFloating & dof) {
@@ -1017,9 +1018,10 @@ DerivationOutput DerivationOutput::fromJSON(
else if (keys == (std::set<std::string_view> { "path", "hashAlgo", "hash" })) {
auto [method, hashType] = methodAlgo();
auto dof = DerivationOutput::CAFixed {
- .ca = ContentAddress::fromParts(
- std::move(method),
- Hash::parseNonSRIUnprefixed((std::string) json["hash"], hashType)),
+ .ca = ContentAddress {
+ .method = std::move(method),
+ .hash = Hash::parseNonSRIUnprefixed((std::string) json["hash"], hashType),
+ },
};
if (dof.path(store, drvName, outputName) != store.parseStorePath((std::string) json["path"]))
throw Error("Path doesn't match derivation output");