aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-17 10:28:54 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-17 10:28:54 -0400
commit2eb493ca51e97228a7dc8e28e414df627cb3a329 (patch)
treec1ea1e2e9ae2caed01d8991739a0f942ae64ec3c /src/libstore
parente12efa365462bf7c65e6b531a7ace4fc1660e2cc (diff)
Fix `DerivationOutput::fromJSON`
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/derivations.cc22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 56f30f2e4..fc76ae7ad 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -997,15 +997,13 @@ DerivationOutput DerivationOutput::fromJSON(
for (const auto & [key, _] : json)
keys.insert(key);
- auto methodAlgo = [&]() -> std::pair<FileIngestionMethod, HashType> {
+ auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashType> {
std::string hashAlgo = json["hashAlgo"];
- auto method = FileIngestionMethod::Flat;
- if (hashAlgo.substr(0, 2) == "r:") {
- method = FileIngestionMethod::Recursive;
- hashAlgo = hashAlgo.substr(2);
- }
- auto hashType = parseHashType(hashAlgo);
- return { method, hashType };
+ // remaining to parse, will be mutated by parsers
+ std::string_view s = hashAlgo;
+ ContentAddressMethod method = ContentAddressMethod::parsePrefix(s);
+ auto hashType = parseHashType(s);
+ return { std::move(method), std::move(hashType) };
};
if (keys == (std::set<std::string_view> { "path" })) {
@@ -1018,7 +1016,7 @@ DerivationOutput DerivationOutput::fromJSON(
auto [method, hashType] = methodAlgo();
auto dof = DerivationOutput::CAFixed {
.ca = ContentAddressWithReferences::fromParts(
- method,
+ std::move(method),
Hash::parseNonSRIUnprefixed((std::string) json["hash"], hashType),
{}),
};
@@ -1030,8 +1028,8 @@ DerivationOutput DerivationOutput::fromJSON(
else if (keys == (std::set<std::string_view> { "hashAlgo" })) {
auto [method, hashType] = methodAlgo();
return DerivationOutput::CAFloating {
- .method = method,
- .hashType = hashType,
+ .method = std::move(method),
+ .hashType = std::move(hashType),
};
}
@@ -1042,7 +1040,7 @@ DerivationOutput DerivationOutput::fromJSON(
else if (keys == (std::set<std::string_view> { "hashAlgo", "impure" })) {
auto [method, hashType] = methodAlgo();
return DerivationOutput::Impure {
- .method = method,
+ .method = std::move(method),
.hashType = hashType,
};
}