1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 13:41:15 +02:00

Don't add StorePathDescriptor for now

We don't need it yet, we can add it back later.
This commit is contained in:
John Ericson 2023-01-23 12:58:11 -05:00
parent c67e0cc58c
commit 4540e7b940
14 changed files with 126 additions and 151 deletions

View file

@ -21,48 +21,45 @@ void ValidPathInfo::sign(const Store & store, const SecretKey & secretKey)
sigs.insert(secretKey.signDetached(fingerprint(store)));
}
std::optional<StorePathDescriptor> ValidPathInfo::fullStorePathDescriptorOpt() const
std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithReferenences() const
{
if (! ca)
return std::nullopt;
return StorePathDescriptor {
.name = std::string { path.name() },
.info = std::visit(overloaded {
[&](const TextHash & th) -> ContentAddressWithReferences {
assert(references.count(path) == 0);
return TextInfo {
th,
.references = references,
};
},
[&](const FixedOutputHash & foh) -> ContentAddressWithReferences {
auto refs = references;
bool hasSelfReference = false;
if (refs.count(path)) {
hasSelfReference = true;
refs.erase(path);
}
return FixedOutputInfo {
foh,
.references = {
.others = std::move(refs),
.self = hasSelfReference,
},
};
},
}, *ca),
};
return std::visit(overloaded {
[&](const TextHash & th) -> ContentAddressWithReferences {
assert(references.count(path) == 0);
return TextInfo {
th,
.references = references,
};
},
[&](const FixedOutputHash & foh) -> ContentAddressWithReferences {
auto refs = references;
bool hasSelfReference = false;
if (refs.count(path)) {
hasSelfReference = true;
refs.erase(path);
}
return FixedOutputInfo {
foh,
.references = {
.others = std::move(refs),
.self = hasSelfReference,
},
};
},
}, *ca);
}
bool ValidPathInfo::isContentAddressed(const Store & store) const
{
auto fullCaOpt = fullStorePathDescriptorOpt();
auto fullCaOpt = contentAddressWithReferenences();
if (! fullCaOpt)
return false;
auto caPath = store.makeFixedOutputPathFromCA(*fullCaOpt);
auto caPath = store.makeFixedOutputPathFromCA(path.name(), *fullCaOpt);
bool res = caPath == path;
@ -102,9 +99,10 @@ Strings ValidPathInfo::shortRefs() const
ValidPathInfo::ValidPathInfo(
const Store & store,
StorePathDescriptor && info,
std::string_view name,
ContentAddressWithReferences && ca,
Hash narHash)
: path(store.makeFixedOutputPathFromCA(info))
: path(store.makeFixedOutputPathFromCA(name, ca))
, narHash(narHash)
{
std::visit(overloaded {
@ -118,7 +116,7 @@ ValidPathInfo::ValidPathInfo(
this->references.insert(path);
this->ca = std::move((FixedOutputHash &&) foi);
},
}, std::move(info.info));
}, std::move(ca));
}