diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-01-14 14:27:28 -0500 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2023-01-14 14:27:28 -0500 |
commit | 056cc1c1b903114f59c536dd9821b46f68516f4e (patch) | |
tree | 7a93772a077355c152c12042ccd9392abc86eb5e /src/libstore/store-api.cc | |
parent | 2e7be46e73293f729358eefc5b464dcb7e2d76bf (diff) | |
parent | 2e41ae9f93af0be2c778dda97e0ee9544a8aca1f (diff) |
Merge remote-tracking branch 'upstream/master' into path-info
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 139 |
1 files changed, 28 insertions, 111 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index a4e98d66b..9446ad132 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1228,117 +1228,6 @@ std::string showPaths(const PathSet & paths) return concatStringsSep(", ", quoteStrings(paths)); } -std::string ValidPathInfo::fingerprint(const Store & store) const -{ - if (narSize == 0) - throw Error("cannot calculate fingerprint of path '%s' because its size is not known", - store.printStorePath(path)); - return - "1;" + store.printStorePath(path) + ";" - + narHash.to_string(Base32, true) + ";" - + std::to_string(narSize) + ";" - + concatStringsSep(",", store.printStorePathSet(referencesPossiblyToSelf())); -} - - -void ValidPathInfo::sign(const Store & store, const SecretKey & secretKey) -{ - sigs.insert(secretKey.signDetached(fingerprint(store))); -} - -std::optional<StorePathDescriptor> ValidPathInfo::fullStorePathDescriptorOpt() const -{ - if (! ca) - return std::nullopt; - - return StorePathDescriptor { - .name = std::string { path.name() }, - .info = std::visit(overloaded { - [&](const TextHash & th) -> ContentAddressWithReferences { - assert(!references.self); - return TextInfo { - th, - .references = references.others, - }; - }, - [&](const FixedOutputHash & foh) -> ContentAddressWithReferences { - return FixedOutputInfo { - foh, - .references = references, - }; - }, - }, *ca), - }; -} - -bool ValidPathInfo::isContentAddressed(const Store & store) const -{ - auto fullCaOpt = fullStorePathDescriptorOpt(); - - if (! fullCaOpt) - return false; - - auto caPath = store.makeFixedOutputPathFromCA(*fullCaOpt); - - bool res = caPath == path; - - if (!res) - printError("warning: path '%s' claims to be content-addressed but isn't", store.printStorePath(path)); - - return res; -} - - -size_t ValidPathInfo::checkSignatures(const Store & store, const PublicKeys & publicKeys) const -{ - if (isContentAddressed(store)) return maxSigs; - - size_t good = 0; - for (auto & sig : sigs) - if (checkSignature(store, publicKeys, sig)) - good++; - return good; -} - - -bool ValidPathInfo::checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const -{ - return verifyDetached(fingerprint(store), sig, publicKeys); -} - - -Strings ValidPathInfo::shortRefs() const -{ - Strings refs; - for (auto & r : referencesPossiblyToSelf()) - refs.push_back(std::string(r.to_string())); - return refs; -} - - -ValidPathInfo::ValidPathInfo( - const Store & store, - StorePathDescriptor && info, - Hash narHash) - : path(store.makeFixedOutputPathFromCA(info)) - , narHash(narHash) -{ - std::visit(overloaded { - [this](TextInfo && ti) { - this->references = { - .others = std::move(ti.references), - .self = false, - }; - this->ca = std::move((TextHash &&) ti); - }, - [this](FixedOutputInfo && foi) { - this->references = std::move(foi.references); - this->ca = std::move((FixedOutputHash &&) foi); - }, - }, std::move(info.info)); -} - - Derivation Store::derivationFromPath(const StorePath & drvPath) { ensurePath(drvPath); @@ -1357,6 +1246,34 @@ Derivation readDerivationCommon(Store& store, const StorePath& drvPath, bool req } } +std::optional<StorePath> Store::getBuildDerivationPath(const StorePath & path) +{ + + if (!path.isDerivation()) { + try { + auto info = queryPathInfo(path); + if (!info->deriver) return std::nullopt; + return *info->deriver; + } catch (InvalidPath &) { + return std::nullopt; + } + } + + if (!settings.isExperimentalFeatureEnabled(Xp::CaDerivations) || !isValidPath(path)) + return path; + + auto drv = readDerivation(path); + if (!drv.type().hasKnownOutputPaths()) { + // The build log is actually attached to the corresponding + // resolved derivation, so we need to get it first + auto resolvedDrv = drv.tryResolve(*this); + if (resolvedDrv) + return writeDerivation(*this, *resolvedDrv, NoRepair, true); + } + + return path; +} + Derivation Store::readDerivation(const StorePath & drvPath) { return readDerivationCommon(*this, drvPath, true); } |