From 87b32bab05ff91981c8847d66cd5502feb44f3b5 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Mar 2020 23:22:10 +0000 Subject: Use `enum struct` and drop prefixes This does a few enums; the rest will be gotten in subsequent commits. --- src/libstore/local-store.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/libstore/local-store.cc') diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index ae7513ad8..f293ecb4a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -580,7 +580,7 @@ uint64_t LocalStore::addValidPath(State & state, state.stmtRegisterValidPath.use() (printStorePath(info.path)) - (info.narHash.to_string(Base16)) + (info.narHash.to_string(Base::Base16)) (info.registrationTime == 0 ? time(0) : info.registrationTime) (info.deriver ? printStorePath(*info.deriver) : "", (bool) info.deriver) (info.narSize, info.narSize != 0) @@ -680,7 +680,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info) { state.stmtUpdatePathInfo.use() (info.narSize, info.narSize != 0) - (info.narHash.to_string(Base16)) + (info.narHash.to_string(Base::Base16)) (info.ultimate ? 1 : 0, info.ultimate) (concatStringsSep(" ", info.sigs), !info.sigs.empty()) (info.ca, !info.ca.empty()) @@ -908,7 +908,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos) StorePathSet paths; for (auto & i : infos) { - assert(i.narHash.type == htSHA256); + assert(i.narHash.type == HashType::SHA256); if (isValidPath_(*state, i.path)) updatePathInfo(*state, i); else @@ -1006,9 +1006,9 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, of the NAR. */ std::unique_ptr hashSink; if (info.ca == "" || !info.references.count(info.path)) - hashSink = std::make_unique(htSHA256); + hashSink = std::make_unique(HashType::SHA256); else - hashSink = std::make_unique(htSHA256, storePathToHash(printStorePath(info.path))); + hashSink = std::make_unique(HashType::SHA256, storePathToHash(printStorePath(info.path))); LambdaSource wrapperSource([&](unsigned char * data, size_t len) -> size_t { size_t n = source.read(data, len); @@ -1081,10 +1081,10 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam sha256); otherwise, compute it here. */ HashResult hash; if (recursive) { - hash.first = hashAlgo == htSHA256 ? h : hashString(htSHA256, dump); + hash.first = hashAlgo == HashType::SHA256 ? h : hashString(HashType::SHA256, dump); hash.second = dump.size(); } else - hash = hashPath(htSHA256, realPath); + hash = hashPath(HashType::SHA256, realPath); optimisePath(realPath); // FIXME: combine with hashPath() @@ -1123,7 +1123,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath, StorePath LocalStore::addTextToStore(const string & name, const string & s, const StorePathSet & references, RepairFlag repair) { - auto hash = hashString(htSHA256, s); + auto hash = hashString(HashType::SHA256, s); auto dstPath = makeTextPath(name, hash, references); addTempRoot(dstPath); @@ -1147,7 +1147,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, StringSink sink; dumpString(s, sink); - auto narHash = hashString(htSHA256, *sink.s); + auto narHash = hashString(HashType::SHA256, *sink.s); optimisePath(realPath); @@ -1233,9 +1233,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking link hashes..."); for (auto & link : readDirectory(linksDir)) { - printMsg(lvlTalkative, "checking contents of '%s'", link.name); + printMsg(Verbosity::Talkative, "checking contents of '%s'", link.name); Path linkPath = linksDir + "/" + link.name; - string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false); + string hash = hashPath(HashType::SHA256, linkPath).first.to_string(Base::Base32, false); if (hash != link.name) { printError( "link '%s' was modified! expected hash '%s', got '%s'", @@ -1253,14 +1253,14 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking store hashes..."); - Hash nullHash(htSHA256); + Hash nullHash(HashType::SHA256); for (auto & i : validPaths) { try { auto info = std::const_pointer_cast(std::shared_ptr(queryPathInfo(i))); /* Check the content hash (optionally - slow). */ - printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i)); + printMsg(Verbosity::Talkative, "checking contents of '%s'", printStorePath(i)); std::unique_ptr hashSink; if (info->ca == "" || !info->references.count(info->path)) -- cgit v1.2.3 From 832bd534dc0ab36fd8267f62b67ab1db1498d2b4 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 22 Mar 2020 23:43:07 -0400 Subject: Store parsed hashes in `DerivationOutput` It's best to detect invalid data as soon as possible, with data types that make storing it impossible. --- src/libstore/local-store.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/libstore/local-store.cc') diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 746f81beb..82a9eb43c 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -557,10 +557,12 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat if (out == drv.outputs.end()) throw Error("derivation '%s' does not have an output named 'out'", printStorePath(drvPath)); - FileIngestionMethod recursive; Hash h; - out->second.parseHashInfo(recursive, h); - - check(makeFixedOutputPath(recursive, h, drvName), out->second.path, "out"); + check( + makeFixedOutputPath( + out->second.hash->method, + out->second.hash->hash, + drvName), + out->second.path, "out"); } else { -- cgit v1.2.3 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/local-store.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstore/local-store.cc') 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 15abb2aa2ba7de06a86e05511f81633616e17d87 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 18 Jun 2020 22:09:22 +0000 Subject: Revert the `enum struct` change Not a regular git revert as there have been many merges and things. --- src/libstore/local-store.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/libstore/local-store.cc') diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 60ad138a3..df4edbbca 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -584,7 +584,7 @@ uint64_t LocalStore::addValidPath(State & state, state.stmtRegisterValidPath.use() (printStorePath(info.path)) - (info.narHash.to_string(Base::Base16, true)) + (info.narHash.to_string(Base16, true)) (info.registrationTime == 0 ? time(0) : info.registrationTime) (info.deriver ? printStorePath(*info.deriver) : "", (bool) info.deriver) (info.narSize, info.narSize != 0) @@ -684,7 +684,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info) { state.stmtUpdatePathInfo.use() (info.narSize, info.narSize != 0) - (info.narHash.to_string(Base::Base16, true)) + (info.narHash.to_string(Base16, true)) (info.ultimate ? 1 : 0, info.ultimate) (concatStringsSep(" ", info.sigs), !info.sigs.empty()) (info.ca, !info.ca.empty()) @@ -895,7 +895,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos) StorePathSet paths; for (auto & i : infos) { - assert(i.narHash.type == HashType::SHA256); + assert(i.narHash.type == htSHA256); if (isValidPath_(*state, i.path)) updatePathInfo(*state, i); else @@ -992,9 +992,9 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, of the NAR. */ std::unique_ptr hashSink; if (info.ca == "" || !info.references.count(info.path)) - hashSink = std::make_unique(HashType::SHA256); + hashSink = std::make_unique(htSHA256); else - hashSink = std::make_unique(HashType::SHA256, std::string(info.path.hashPart())); + hashSink = std::make_unique(htSHA256, std::string(info.path.hashPart())); LambdaSource wrapperSource([&](unsigned char * data, size_t len) -> size_t { size_t n = source.read(data, len); @@ -1008,7 +1008,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, if (hashResult.first != info.narHash) throw Error("hash mismatch importing path '%s';\n wanted: %s\n got: %s", - printStorePath(info.path), info.narHash.to_string(Base::Base32, true), hashResult.first.to_string(Base::Base32, true)); + printStorePath(info.path), info.narHash.to_string(Base32, true), hashResult.first.to_string(Base32, true)); if (hashResult.second != info.narSize) throw Error("size mismatch importing path '%s';\n wanted: %s\n got: %s", @@ -1067,10 +1067,10 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam sha256); otherwise, compute it here. */ HashResult hash; if (method == FileIngestionMethod::Recursive) { - hash.first = hashAlgo == HashType::SHA256 ? h : hashString(HashType::SHA256, dump); + hash.first = hashAlgo == htSHA256 ? h : hashString(htSHA256, dump); hash.second = dump.size(); } else - hash = hashPath(HashType::SHA256, realPath); + hash = hashPath(htSHA256, realPath); optimisePath(realPath); // FIXME: combine with hashPath() @@ -1109,7 +1109,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath, StorePath LocalStore::addTextToStore(const string & name, const string & s, const StorePathSet & references, RepairFlag repair) { - auto hash = hashString(HashType::SHA256, s); + auto hash = hashString(htSHA256, s); auto dstPath = makeTextPath(name, hash, references); addTempRoot(dstPath); @@ -1133,7 +1133,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, StringSink sink; dumpString(s, sink); - auto narHash = hashString(HashType::SHA256, *sink.s); + auto narHash = hashString(htSHA256, *sink.s); optimisePath(realPath); @@ -1141,7 +1141,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s, info.narHash = narHash; info.narSize = sink.s->size(); info.references = references; - info.ca = "text:" + hash.to_string(Base::Base32, true); + info.ca = "text:" + hash.to_string(Base32, true); registerValidPath(info); } @@ -1219,9 +1219,9 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking link hashes..."); for (auto & link : readDirectory(linksDir)) { - printMsg(Verbosity::Talkative, "checking contents of '%s'", link.name); + printMsg(lvlTalkative, "checking contents of '%s'", link.name); Path linkPath = linksDir + "/" + link.name; - string hash = hashPath(HashType::SHA256, linkPath).first.to_string(Base::Base32, false); + string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false); if (hash != link.name) { logError({ .name = "Invalid hash", @@ -1242,14 +1242,14 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) printInfo("checking store hashes..."); - Hash nullHash(HashType::SHA256); + Hash nullHash(htSHA256); for (auto & i : validPaths) { try { auto info = std::const_pointer_cast(std::shared_ptr(queryPathInfo(i))); /* Check the content hash (optionally - slow). */ - printMsg(Verbosity::Talkative, "checking contents of '%s'", printStorePath(i)); + printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i)); std::unique_ptr hashSink; if (info->ca == "" || !info->references.count(info->path)) @@ -1264,7 +1264,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair) logError({ .name = "Invalid hash - path modified", .hint = hintfmt("path '%s' was modified! expected hash '%s', got '%s'", - printStorePath(i), info->narHash.to_string(Base::Base32, true), current.first.to_string(Base::Base32, true)) + printStorePath(i), info->narHash.to_string(Base32, true), current.first.to_string(Base32, true)) }); if (repair) repairPath(i); else errors = true; } else { -- cgit v1.2.3