diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 8a8039b6bff..b55837c9e4d 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -74,7 +74,7 @@ DownloadFileResult downloadFile( StringSink sink; dumpString(res.data, sink); auto hash = hashString(HashAlgorithm::SHA256, res.data); - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( *store, name, FixedOutputInfo{ @@ -82,8 +82,7 @@ DownloadFileResult downloadFile( .hash = hash, .references = {}, }, - hashString(HashAlgorithm::SHA256, sink.s), - }; + hashString(HashAlgorithm::SHA256, sink.s)); info.narSize = sink.s.size(); auto source = StringSource{sink.s}; store->addToStore(info, source, NoRepair, NoCheckSigs); diff --git a/src/libstore-tests/nar-info.cc b/src/libstore-tests/nar-info.cc index a73df119051..751c5e305bb 100644 --- a/src/libstore-tests/nar-info.cc +++ b/src/libstore-tests/nar-info.cc @@ -23,7 +23,7 @@ class NarInfoTest : public CharacterizationTest, public LibStoreTest static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo) { - NarInfo info = ValidPathInfo{ + auto info = NarInfo::makeFromCA( store, "foo", FixedOutputInfo{ @@ -41,8 +41,7 @@ static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo) .self = true, }, }, - Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="), - }; + Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=")); info.narSize = 34878; if (includeImpureInfo) { info.deriver = StorePath{ diff --git a/src/libstore-tests/path-info.cc b/src/libstore-tests/path-info.cc index de5c9515083..63310c1c391 100644 --- a/src/libstore-tests/path-info.cc +++ b/src/libstore-tests/path-info.cc @@ -29,7 +29,7 @@ static UnkeyedValidPathInfo makeEmpty() static ValidPathInfo makeFullKeyed(const Store & store, bool includeImpureInfo) { - ValidPathInfo info = ValidPathInfo{ + auto info = ValidPathInfo::makeFromCA( store, "foo", FixedOutputInfo{ @@ -47,8 +47,7 @@ static ValidPathInfo makeFullKeyed(const Store & store, bool includeImpureInfo) .self = true, }, }, - Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="), - }; + Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=")); info.narSize = 34878; if (includeImpureInfo) { info.deriver = StorePath{ diff --git a/src/libstore-tests/serve-protocol.cc b/src/libstore-tests/serve-protocol.cc index 4cd7f101b56..b513e13656b 100644 --- a/src/libstore-tests/serve-protocol.cc +++ b/src/libstore-tests/serve-protocol.cc @@ -274,7 +274,7 @@ VERSIONED_CHARACTERIZATION_TEST( info; }), ({ - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( store, "foo", FixedOutputInfo{ @@ -291,8 +291,7 @@ VERSIONED_CHARACTERIZATION_TEST( .self = true, }, }, - Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="), - }; + Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=")); info.deriver = StorePath{ "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv", }; diff --git a/src/libstore-tests/worker-protocol.cc b/src/libstore-tests/worker-protocol.cc index a761c96dd81..823d8d85a44 100644 --- a/src/libstore-tests/worker-protocol.cc +++ b/src/libstore-tests/worker-protocol.cc @@ -515,7 +515,7 @@ VERSIONED_CHARACTERIZATION_TEST( info; }), ({ - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( store, "foo", FixedOutputInfo{ @@ -532,8 +532,7 @@ VERSIONED_CHARACTERIZATION_TEST( .self = true, }, }, - Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="), - }; + Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=")); info.registrationTime = 23423; info.narSize = 34878; info; diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index f4e06305a86..e08a1449bd4 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -366,7 +366,7 @@ StorePath BinaryCacheStore::addToStoreFromDump( repair, CheckSigs, [&](HashResult nar) { - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( *this, name, ContentAddressWithReferences::fromParts( @@ -378,8 +378,7 @@ StorePath BinaryCacheStore::addToStoreFromDump( // without modulus .self = false, }), - nar.hash, - }; + nar.hash); info.narSize = nar.numBytesDigested; return info; }) @@ -484,7 +483,7 @@ StorePath BinaryCacheStore::addToStore( repair, CheckSigs, [&](HashResult nar) { - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( *this, name, ContentAddressWithReferences::fromParts( @@ -496,8 +495,7 @@ StorePath BinaryCacheStore::addToStore( // without modulus .self = false, }), - nar.hash, - }; + nar.hash); info.narSize = nar.numBytesDigested; return info; }) diff --git a/src/libstore/include/nix/store/nar-info.hh b/src/libstore/include/nix/store/nar-info.hh index 39d75b0a90d..1684837c690 100644 --- a/src/libstore/include/nix/store/nar-info.hh +++ b/src/libstore/include/nix/store/nar-info.hh @@ -18,19 +18,20 @@ struct NarInfo : ValidPathInfo NarInfo() = delete; - NarInfo(const StoreDirConfig & store, std::string name, ContentAddressWithReferences ca, Hash narHash) - : ValidPathInfo(store, std::move(name), std::move(ca), narHash) + NarInfo(ValidPathInfo info) + : ValidPathInfo{std::move(info)} { } NarInfo(StorePath path, Hash narHash) - : ValidPathInfo(std::move(path), narHash) + : NarInfo{ValidPathInfo{std::move(path), UnkeyedValidPathInfo(narHash)}} { } - NarInfo(const ValidPathInfo & info) - : ValidPathInfo(info) + static NarInfo + makeFromCA(const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences ca, Hash narHash) { + return ValidPathInfo::makeFromCA(store, std::move(name), std::move(ca), narHash); } NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence); diff --git a/src/libstore/include/nix/store/path-info.hh b/src/libstore/include/nix/store/path-info.hh index 9f341198c51..cbc5abdb442 100644 --- a/src/libstore/include/nix/store/path-info.hh +++ b/src/libstore/include/nix/store/path-info.hh @@ -179,8 +179,8 @@ struct ValidPathInfo : UnkeyedValidPathInfo : UnkeyedValidPathInfo(info) , path(path) {}; - ValidPathInfo( - const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash); + static ValidPathInfo + makeFromCA(const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash); }; static_assert(std::is_move_assignable_v); diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index f848ddc706d..4cadf528241 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1311,7 +1311,7 @@ StorePath LocalStore::addToStoreFromDump( syncParent(realPath); } - ValidPathInfo info{*this, name, std::move(desc), narHash.hash}; + auto info = ValidPathInfo::makeFromCA(*this, name, std::move(desc), narHash.hash); info.narSize = narHash.numBytesDigested; registerValidPath(info); } diff --git a/src/libstore/make-content-addressed.cc b/src/libstore/make-content-addressed.cc index ce4a36849d8..4a7b21c3b12 100644 --- a/src/libstore/make-content-addressed.cc +++ b/src/libstore/make-content-addressed.cc @@ -45,7 +45,7 @@ std::map makeContentAddressed(Store & srcStore, Store & ds auto narModuloHash = hashModuloSink.finish().hash; - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( dstStore, path.name(), FixedOutputInfo{ @@ -53,8 +53,7 @@ std::map makeContentAddressed(Store & srcStore, Store & ds .hash = narModuloHash, .references = std::move(refs), }, - Hash::dummy, - }; + Hash::dummy); printInfo("rewriting '%s' to '%s'", pathS, dstStore.printStorePath(info.path)); diff --git a/src/libstore/path-info.cc b/src/libstore/path-info.cc index e3de5949dbe..270c532bb31 100644 --- a/src/libstore/path-info.cc +++ b/src/libstore/path-info.cc @@ -124,25 +124,29 @@ Strings ValidPathInfo::shortRefs() const return refs; } -ValidPathInfo::ValidPathInfo( +ValidPathInfo ValidPathInfo::makeFromCA( const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash) - : UnkeyedValidPathInfo(narHash) - , path(store.makeFixedOutputPathFromCA(name, ca)) { - this->ca = ContentAddress{ + ValidPathInfo res{ + store.makeFixedOutputPathFromCA(name, ca), + narHash, + }; + res.ca = ContentAddress{ .method = ca.getMethod(), .hash = ca.getHash(), }; - std::visit( + res.references = std::visit( overloaded{ - [this](TextInfo && ti) { this->references = std::move(ti.references); }, - [this](FixedOutputInfo && foi) { - this->references = std::move(foi.references.others); + [&](TextInfo && ti) { return std::move(ti.references); }, + [&](FixedOutputInfo && foi) { + auto references = std::move(foi.references.others); if (foi.references.self) - this->references.insert(path); + references.insert(res.path); + return references; }, }, std::move(ca).raw); + return res; } nlohmann::json diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index ada57b358db..17748ec530a 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -269,7 +269,7 @@ ValidPathInfo Store::addToStoreSlow( if (expectedCAHash && expectedCAHash != hash) throw Error("hash mismatch for '%s'", srcPath); - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( *this, name, ContentAddressWithReferences::fromParts( @@ -279,8 +279,7 @@ ValidPathInfo Store::addToStoreSlow( .others = references, .self = false, }), - narHash, - }; + narHash); info.narSize = narSize; if (!isValidPath(info.path)) { diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index d6979ab5f7a..770bdad4d3e 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -1591,12 +1591,11 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs() assert(false); }(); - ValidPathInfo newInfo0{ + auto newInfo0 = ValidPathInfo::makeFromCA( store, outputPathName(drv.name, outputName), ContentAddressWithReferences::fromParts(outputHash.method, std::move(got), rewriteRefs()), - Hash::dummy, - }; + Hash::dummy); if (*scratchPath != newInfo0.path) { // If the path has some self-references, we need to rewrite // them. diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 0ed1face509..68005171fd0 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -257,7 +257,7 @@ struct ProfileManifest auto narHash = hashString(HashAlgorithm::SHA256, sink.s); - ValidPathInfo info{ + auto info = ValidPathInfo::makeFromCA( *store, "profile", FixedOutputInfo{ @@ -270,8 +270,7 @@ struct ProfileManifest .self = false, }, }, - narHash, - }; + narHash); info.narSize = sink.s.size(); StringSource source(sink.s);