mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #13982 from obsidiansystems/path-info-static-function
`ValidPathInfo`, `NarInfo`, turn funky constructor into static method
This commit is contained in:
commit
5bc96798b1
14 changed files with 44 additions and 50 deletions
|
|
@ -74,7 +74,7 @@ DownloadFileResult downloadFile(
|
||||||
StringSink sink;
|
StringSink sink;
|
||||||
dumpString(res.data, sink);
|
dumpString(res.data, sink);
|
||||||
auto hash = hashString(HashAlgorithm::SHA256, res.data);
|
auto hash = hashString(HashAlgorithm::SHA256, res.data);
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
*store,
|
*store,
|
||||||
name,
|
name,
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -82,8 +82,7 @@ DownloadFileResult downloadFile(
|
||||||
.hash = hash,
|
.hash = hash,
|
||||||
.references = {},
|
.references = {},
|
||||||
},
|
},
|
||||||
hashString(HashAlgorithm::SHA256, sink.s),
|
hashString(HashAlgorithm::SHA256, sink.s));
|
||||||
};
|
|
||||||
info.narSize = sink.s.size();
|
info.narSize = sink.s.size();
|
||||||
auto source = StringSource{sink.s};
|
auto source = StringSource{sink.s};
|
||||||
store->addToStore(info, source, NoRepair, NoCheckSigs);
|
store->addToStore(info, source, NoRepair, NoCheckSigs);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class NarInfoTest : public CharacterizationTest, public LibStoreTest
|
||||||
|
|
||||||
static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo)
|
static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo)
|
||||||
{
|
{
|
||||||
NarInfo info = ValidPathInfo{
|
auto info = NarInfo::makeFromCA(
|
||||||
store,
|
store,
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -41,8 +41,7 @@ static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo)
|
||||||
.self = true,
|
.self = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="));
|
||||||
};
|
|
||||||
info.narSize = 34878;
|
info.narSize = 34878;
|
||||||
if (includeImpureInfo) {
|
if (includeImpureInfo) {
|
||||||
info.deriver = StorePath{
|
info.deriver = StorePath{
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ static UnkeyedValidPathInfo makeEmpty()
|
||||||
|
|
||||||
static ValidPathInfo makeFullKeyed(const Store & store, bool includeImpureInfo)
|
static ValidPathInfo makeFullKeyed(const Store & store, bool includeImpureInfo)
|
||||||
{
|
{
|
||||||
ValidPathInfo info = ValidPathInfo{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
store,
|
store,
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -47,8 +47,7 @@ static ValidPathInfo makeFullKeyed(const Store & store, bool includeImpureInfo)
|
||||||
.self = true,
|
.self = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="));
|
||||||
};
|
|
||||||
info.narSize = 34878;
|
info.narSize = 34878;
|
||||||
if (includeImpureInfo) {
|
if (includeImpureInfo) {
|
||||||
info.deriver = StorePath{
|
info.deriver = StorePath{
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
info;
|
info;
|
||||||
}),
|
}),
|
||||||
({
|
({
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
store,
|
store,
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -291,8 +291,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
.self = true,
|
.self = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="));
|
||||||
};
|
|
||||||
info.deriver = StorePath{
|
info.deriver = StorePath{
|
||||||
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -515,7 +515,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
info;
|
info;
|
||||||
}),
|
}),
|
||||||
({
|
({
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
store,
|
store,
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -532,8 +532,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
.self = true,
|
.self = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
|
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="));
|
||||||
};
|
|
||||||
info.registrationTime = 23423;
|
info.registrationTime = 23423;
|
||||||
info.narSize = 34878;
|
info.narSize = 34878;
|
||||||
info;
|
info;
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ StorePath BinaryCacheStore::addToStoreFromDump(
|
||||||
repair,
|
repair,
|
||||||
CheckSigs,
|
CheckSigs,
|
||||||
[&](HashResult nar) {
|
[&](HashResult nar) {
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
*this,
|
*this,
|
||||||
name,
|
name,
|
||||||
ContentAddressWithReferences::fromParts(
|
ContentAddressWithReferences::fromParts(
|
||||||
|
|
@ -378,8 +378,7 @@ StorePath BinaryCacheStore::addToStoreFromDump(
|
||||||
// without modulus
|
// without modulus
|
||||||
.self = false,
|
.self = false,
|
||||||
}),
|
}),
|
||||||
nar.hash,
|
nar.hash);
|
||||||
};
|
|
||||||
info.narSize = nar.numBytesDigested;
|
info.narSize = nar.numBytesDigested;
|
||||||
return info;
|
return info;
|
||||||
})
|
})
|
||||||
|
|
@ -484,7 +483,7 @@ StorePath BinaryCacheStore::addToStore(
|
||||||
repair,
|
repair,
|
||||||
CheckSigs,
|
CheckSigs,
|
||||||
[&](HashResult nar) {
|
[&](HashResult nar) {
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
*this,
|
*this,
|
||||||
name,
|
name,
|
||||||
ContentAddressWithReferences::fromParts(
|
ContentAddressWithReferences::fromParts(
|
||||||
|
|
@ -496,8 +495,7 @@ StorePath BinaryCacheStore::addToStore(
|
||||||
// without modulus
|
// without modulus
|
||||||
.self = false,
|
.self = false,
|
||||||
}),
|
}),
|
||||||
nar.hash,
|
nar.hash);
|
||||||
};
|
|
||||||
info.narSize = nar.numBytesDigested;
|
info.narSize = nar.numBytesDigested;
|
||||||
return info;
|
return info;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,20 @@ struct NarInfo : ValidPathInfo
|
||||||
|
|
||||||
NarInfo() = delete;
|
NarInfo() = delete;
|
||||||
|
|
||||||
NarInfo(const StoreDirConfig & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
|
NarInfo(ValidPathInfo info)
|
||||||
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
|
: ValidPathInfo{std::move(info)}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NarInfo(StorePath path, Hash narHash)
|
NarInfo(StorePath path, Hash narHash)
|
||||||
: ValidPathInfo(std::move(path), narHash)
|
: NarInfo{ValidPathInfo{std::move(path), UnkeyedValidPathInfo(narHash)}}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NarInfo(const ValidPathInfo & info)
|
static NarInfo
|
||||||
: ValidPathInfo(info)
|
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);
|
NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence);
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,8 @@ struct ValidPathInfo : UnkeyedValidPathInfo
|
||||||
: UnkeyedValidPathInfo(info)
|
: UnkeyedValidPathInfo(info)
|
||||||
, path(path) {};
|
, path(path) {};
|
||||||
|
|
||||||
ValidPathInfo(
|
static ValidPathInfo
|
||||||
const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
|
makeFromCA(const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::is_move_assignable_v<ValidPathInfo>);
|
static_assert(std::is_move_assignable_v<ValidPathInfo>);
|
||||||
|
|
|
||||||
|
|
@ -1311,7 +1311,7 @@ StorePath LocalStore::addToStoreFromDump(
|
||||||
syncParent(realPath);
|
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;
|
info.narSize = narHash.numBytesDigested;
|
||||||
registerValidPath(info);
|
registerValidPath(info);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ std::map<StorePath, StorePath> makeContentAddressed(Store & srcStore, Store & ds
|
||||||
|
|
||||||
auto narModuloHash = hashModuloSink.finish().hash;
|
auto narModuloHash = hashModuloSink.finish().hash;
|
||||||
|
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
dstStore,
|
dstStore,
|
||||||
path.name(),
|
path.name(),
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -53,8 +53,7 @@ std::map<StorePath, StorePath> makeContentAddressed(Store & srcStore, Store & ds
|
||||||
.hash = narModuloHash,
|
.hash = narModuloHash,
|
||||||
.references = std::move(refs),
|
.references = std::move(refs),
|
||||||
},
|
},
|
||||||
Hash::dummy,
|
Hash::dummy);
|
||||||
};
|
|
||||||
|
|
||||||
printInfo("rewriting '%s' to '%s'", pathS, dstStore.printStorePath(info.path));
|
printInfo("rewriting '%s' to '%s'", pathS, dstStore.printStorePath(info.path));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,25 +124,29 @@ Strings ValidPathInfo::shortRefs() const
|
||||||
return refs;
|
return refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidPathInfo::ValidPathInfo(
|
ValidPathInfo ValidPathInfo::makeFromCA(
|
||||||
const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash)
|
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(),
|
.method = ca.getMethod(),
|
||||||
.hash = ca.getHash(),
|
.hash = ca.getHash(),
|
||||||
};
|
};
|
||||||
std::visit(
|
res.references = std::visit(
|
||||||
overloaded{
|
overloaded{
|
||||||
[this](TextInfo && ti) { this->references = std::move(ti.references); },
|
[&](TextInfo && ti) { return std::move(ti.references); },
|
||||||
[this](FixedOutputInfo && foi) {
|
[&](FixedOutputInfo && foi) {
|
||||||
this->references = std::move(foi.references.others);
|
auto references = std::move(foi.references.others);
|
||||||
if (foi.references.self)
|
if (foi.references.self)
|
||||||
this->references.insert(path);
|
references.insert(res.path);
|
||||||
|
return references;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
std::move(ca).raw);
|
std::move(ca).raw);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json
|
nlohmann::json
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ ValidPathInfo Store::addToStoreSlow(
|
||||||
if (expectedCAHash && expectedCAHash != hash)
|
if (expectedCAHash && expectedCAHash != hash)
|
||||||
throw Error("hash mismatch for '%s'", srcPath);
|
throw Error("hash mismatch for '%s'", srcPath);
|
||||||
|
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
*this,
|
*this,
|
||||||
name,
|
name,
|
||||||
ContentAddressWithReferences::fromParts(
|
ContentAddressWithReferences::fromParts(
|
||||||
|
|
@ -279,8 +279,7 @@ ValidPathInfo Store::addToStoreSlow(
|
||||||
.others = references,
|
.others = references,
|
||||||
.self = false,
|
.self = false,
|
||||||
}),
|
}),
|
||||||
narHash,
|
narHash);
|
||||||
};
|
|
||||||
info.narSize = narSize;
|
info.narSize = narSize;
|
||||||
|
|
||||||
if (!isValidPath(info.path)) {
|
if (!isValidPath(info.path)) {
|
||||||
|
|
|
||||||
|
|
@ -1591,12 +1591,11 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
|
||||||
assert(false);
|
assert(false);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
ValidPathInfo newInfo0{
|
auto newInfo0 = ValidPathInfo::makeFromCA(
|
||||||
store,
|
store,
|
||||||
outputPathName(drv.name, outputName),
|
outputPathName(drv.name, outputName),
|
||||||
ContentAddressWithReferences::fromParts(outputHash.method, std::move(got), rewriteRefs()),
|
ContentAddressWithReferences::fromParts(outputHash.method, std::move(got), rewriteRefs()),
|
||||||
Hash::dummy,
|
Hash::dummy);
|
||||||
};
|
|
||||||
if (*scratchPath != newInfo0.path) {
|
if (*scratchPath != newInfo0.path) {
|
||||||
// If the path has some self-references, we need to rewrite
|
// If the path has some self-references, we need to rewrite
|
||||||
// them.
|
// them.
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ struct ProfileManifest
|
||||||
|
|
||||||
auto narHash = hashString(HashAlgorithm::SHA256, sink.s);
|
auto narHash = hashString(HashAlgorithm::SHA256, sink.s);
|
||||||
|
|
||||||
ValidPathInfo info{
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
*store,
|
*store,
|
||||||
"profile",
|
"profile",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
|
|
@ -270,8 +270,7 @@ struct ProfileManifest
|
||||||
.self = false,
|
.self = false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
narHash,
|
narHash);
|
||||||
};
|
|
||||||
info.narSize = sink.s.size();
|
info.narSize = sink.s.size();
|
||||||
|
|
||||||
StringSource source(sink.s);
|
StringSource source(sink.s);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue