From 450dcf2c1b60a36f5ffeab2411805287d122bcdd Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 15:52:13 +0000 Subject: Remove `HashType::Unknown` Instead, `Hash` uses `std::optional`. In the future, we may also make `Hash` itself require a known hash type, encoraging people to use `std::optional` instead. --- src/libstore/build.cc | 6 +++--- src/libstore/builtins/fetchurl.cc | 2 +- src/libstore/derivations.cc | 2 -- src/libstore/export-import.cc | 2 +- src/libstore/local-store.cc | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/build.cc b/src/libstore/build.cc index ae7ba6549..b93855f79 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3726,8 +3726,8 @@ void DerivationGoal::registerOutputs() /* Check the hash. In hash mode, move the path produced by the derivation to its content-addressed location. */ Hash h2 = outputHashMode == FileIngestionMethod::Recursive - ? hashPath(h.type, actualPath).first - : hashFile(h.type, actualPath); + ? hashPath(*h.type, actualPath).first + : hashFile(*h.type, actualPath); auto dest = worker.store.makeFixedOutputPath(outputHashMode, h2, i.second.path.name()); @@ -4999,7 +4999,7 @@ bool Worker::pathContentsGood(const StorePath & path) if (!pathExists(store.printStorePath(path))) res = false; else { - HashResult current = hashPath(info->narHash.type, store.printStorePath(path)); + HashResult current = hashPath(*info->narHash.type, store.printStorePath(path)); Hash nullHash(HashType::SHA256); res = info->narHash == nullHash || info->narHash == current.first; } diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index b70e960f8..831431437 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -65,7 +65,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; auto ht = parseHashType(getAttr("outputHashAlgo")); auto h = Hash(getAttr("outputHash"), ht); - fetch(hashedMirror + printHashType(h.type) + "/" + h.to_string(Base::Base16, false)); + fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base::Base16, false)); return; } catch (Error & e) { debug(e.what()); diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index a90c9b86c..d7b677185 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -20,8 +20,6 @@ void DerivationOutput::parseHashInfo(FileIngestionMethod & recursive, Hash & has } HashType hashType = parseHashType(algo); - if (hashType == HashType::Unknown) - throw Error("unknown hash algorithm '%s'", algo); hash = Hash(this->hash, hashType); } diff --git a/src/libstore/export-import.cc b/src/libstore/export-import.cc index 8a5e9d08e..e96b5610a 100644 --- a/src/libstore/export-import.cc +++ b/src/libstore/export-import.cc @@ -54,7 +54,7 @@ void Store::exportPath(const StorePath & path, Sink & sink) filesystem corruption from spreading to other machines. Don't complain if the stored hash is zero (unknown). */ Hash hash = hashAndWriteSink.currentHash(); - if (hash != info->narHash && info->narHash != Hash(info->narHash.type)) + if (hash != info->narHash && info->narHash != Hash(*info->narHash.type)) throw Error("hash of path '%s' has changed from '%s' to '%s'!", printStorePath(path), info->narHash.to_string(), hash.to_string()); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 7f0d5af25..5b18ebf95 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1264,9 +1264,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) std::unique_ptr hashSink; if (info->ca == "" || !info->references.count(info->path)) - hashSink = std::make_unique(info->narHash.type); + hashSink = std::make_unique(*info->narHash.type); else - hashSink = std::make_unique(info->narHash.type, storePathToHash(printStorePath(info->path))); + hashSink = std::make_unique(*info->narHash.type, storePathToHash(printStorePath(info->path))); dumpPath(Store::toRealPath(i), *hashSink); auto current = hashSink->finish(); -- cgit v1.2.3 From 406dbb7fce32f7d80b02f560d91c956698b58d6e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 21:09:15 +0000 Subject: `outputHashAlgo` can be blank so parse accordingly It is blank for SRI hashes. --- src/libstore/builtins/fetchurl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstore') diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index 831431437..770df2927 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -63,7 +63,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) for (auto hashedMirror : settings.hashedMirrors.get()) try { if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; - auto ht = parseHashType(getAttr("outputHashAlgo")); + auto ht = parseHashTypeOpt(getAttr("outputHashAlgo")); auto h = Hash(getAttr("outputHash"), ht); fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base::Base16, false)); return; -- cgit v1.2.3