aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-02 15:52:13 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-02 15:52:13 +0000
commit450dcf2c1b60a36f5ffeab2411805287d122bcdd (patch)
treed1fe49020e97198147483f42454da46f36e42094 /src/libstore
parent6dd471ebf6b9a4996405398093ccb371b8abdf2f (diff)
Remove `HashType::Unknown`
Instead, `Hash` uses `std::optional<HashType>`. In the future, we may also make `Hash` itself require a known hash type, encoraging people to use `std::optional<Hash>` instead.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build.cc6
-rw-r--r--src/libstore/builtins/fetchurl.cc2
-rw-r--r--src/libstore/derivations.cc2
-rw-r--r--src/libstore/export-import.cc2
-rw-r--r--src/libstore/local-store.cc4
5 files changed, 7 insertions, 9 deletions
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<AbstractHashSink> hashSink;
if (info->ca == "" || !info->references.count(info->path))
- hashSink = std::make_unique<HashSink>(info->narHash.type);
+ hashSink = std::make_unique<HashSink>(*info->narHash.type);
else
- hashSink = std::make_unique<HashModuloSink>(info->narHash.type, storePathToHash(printStorePath(info->path)));
+ hashSink = std::make_unique<HashModuloSink>(*info->narHash.type, storePathToHash(printStorePath(info->path)));
dumpPath(Store::toRealPath(i), *hashSink);
auto current = hashSink->finish();