mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
ValidPathInfo, NarInfo, turn funky constructor into static method
This is more flexible, and needed for me to be able to reshuffle the inheritance bureaucracy to make the JSON instances more precise.
This commit is contained in:
parent
465d627f7f
commit
74be28820c
14 changed files with 44 additions and 50 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<ValidPathInfo>);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ std::map<StorePath, StorePath> 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<StorePath, StorePath> 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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue