Don't add StorePathDescriptor for now

We don't need it yet, we can add it back later.
This commit is contained in:
John Ericson 2023-01-23 12:58:11 -05:00
parent c67e0cc58c
commit 4540e7b940
14 changed files with 126 additions and 151 deletions

View file

@ -72,15 +72,13 @@ DownloadFileResult downloadFile(
auto hash = hashString(htSHA256, res.data);
ValidPathInfo info {
*store,
{
.name = name,
.info = FixedOutputInfo {
{
.method = FileIngestionMethod::Flat,
.hash = hash,
},
.references = {},
name,
FixedOutputInfo {
{
.method = FileIngestionMethod::Flat,
.hash = hash,
},
.references = {},
},
hashString(htSHA256, sink.s),
};

View file

@ -307,17 +307,15 @@ StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view n
return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info {
*this,
{
.name = std::string { name },
.info = FixedOutputInfo {
{
.method = method,
.hash = nar.first,
},
.references = {
.others = references,
.self = false,
},
name,
FixedOutputInfo {
{
.method = method,
.hash = nar.first,
},
.references = {
.others = references,
.self = false,
},
},
nar.first,
@ -427,17 +425,15 @@ StorePath BinaryCacheStore::addToStore(
return addToStoreCommon(*source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info {
*this,
{
.name = std::string { name },
.info = FixedOutputInfo {
{
.method = method,
.hash = h,
},
.references = {
.others = references,
.self = false,
},
name,
FixedOutputInfo {
{
.method = method,
.hash = h,
},
.references = {
.others = references,
.self = false,
},
},
nar.first,
@ -465,12 +461,10 @@ StorePath BinaryCacheStore::addTextToStore(
return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info {
*this,
{
.name = std::string { name },
.info = TextInfo {
{ .hash = textHash },
references,
},
std::string { name },
TextInfo {
{ .hash = textHash },
references,
},
nar.first,
};

View file

@ -2475,15 +2475,13 @@ DrvOutputs LocalDerivationGoal::registerOutputs()
auto got = caSink.finish().first;
ValidPathInfo newInfo0 {
worker.store,
{
.name = outputPathName(drv->name, outputName),
.info = FixedOutputInfo {
{
.method = outputHash.method,
.hash = got,
},
.references = rewriteRefs(),
outputPathName(drv->name, outputName),
FixedOutputInfo {
{
.method = outputHash.method,
.hash = got,
},
.references = rewriteRefs(),
},
Hash::dummy,
};

View file

@ -95,10 +95,9 @@ void PathSubstitutionGoal::tryNext()
subs.pop_front();
if (ca) {
subPath = sub->makeFixedOutputPathFromCA({
.name = std::string { storePath.name() },
.info = caWithoutRefs(*ca),
});
subPath = sub->makeFixedOutputPathFromCA(
std::string { storePath.name() },
caWithoutRefs(*ca));
if (sub->storeDir == worker.store.storeDir)
assert(subPath == storePath);
} else if (sub->storeDir != worker.store.storeDir) {

View file

@ -132,11 +132,4 @@ typedef std::variant<
ContentAddressWithReferences caWithoutRefs(const ContentAddress &);
struct StorePathDescriptor {
std::string name;
ContentAddressWithReferences info;
GENERATE_CMP(StorePathDescriptor, me->name, me->info);
};
}

View file

@ -1136,10 +1136,9 @@ void LocalStore::querySubstitutablePathInfos(const StorePathCAMap & paths, Subst
// Recompute store path so that we can use a different store root.
if (path.second) {
subPath = makeFixedOutputPathFromCA({
.name = std::string { path.first.name() },
.info = caWithoutRefs(*path.second),
});
subPath = makeFixedOutputPathFromCA(
path.first.name(),
caWithoutRefs(*path.second));
if (sub->storeDir == storeDir)
assert(subPath == path.first);
if (subPath != path.first)
@ -1417,21 +1416,18 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
auto [hash, size] = hashSink->finish();
auto desc = StorePathDescriptor {
std::string { name },
FixedOutputInfo {
{
.method = method,
.hash = hash,
},
.references = {
.others = references,
.self = false,
},
ContentAddressWithReferences desc = FixedOutputInfo {
{
.method = method,
.hash = hash,
},
.references = {
.others = references,
.self = false,
},
};
auto dstPath = makeFixedOutputPathFromCA(desc);
auto dstPath = makeFixedOutputPathFromCA(name, desc);
addTempRoot(dstPath);
@ -1475,7 +1471,12 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
optimisePath(realPath, repair);
ValidPathInfo info { *this, std::move(desc), narHash.first };
ValidPathInfo info {
*this,
name,
std::move(desc),
narHash.first
};
info.narSize = narHash.second;
registerValidPath(info);
}

View file

@ -49,15 +49,13 @@ std::map<StorePath, StorePath> makeContentAddressed(
ValidPathInfo info {
dstStore,
StorePathDescriptor {
.name = std::string { path.name() },
.info = FixedOutputInfo {
{
.method = FileIngestionMethod::Recursive,
.hash = narModuloHash,
},
.references = std::move(refs),
path.name(),
FixedOutputInfo {
{
.method = FileIngestionMethod::Recursive,
.hash = narModuloHash,
},
.references = std::move(refs),
},
Hash::dummy,
};

View file

@ -16,8 +16,8 @@ struct NarInfo : ValidPathInfo
uint64_t fileSize = 0;
NarInfo() = delete;
NarInfo(const Store & store, StorePathDescriptor && ca, Hash narHash)
: ValidPathInfo(store, std::move(ca), narHash)
NarInfo(const Store & store, std::string && name, ContentAddressWithReferences && ca, Hash narHash)
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
{ }
NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
NarInfo(const ValidPathInfo & info) : ValidPathInfo(info) { }

View file

@ -21,48 +21,45 @@ void ValidPathInfo::sign(const Store & store, const SecretKey & secretKey)
sigs.insert(secretKey.signDetached(fingerprint(store)));
}
std::optional<StorePathDescriptor> ValidPathInfo::fullStorePathDescriptorOpt() const
std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithReferenences() const
{
if (! ca)
return std::nullopt;
return StorePathDescriptor {
.name = std::string { path.name() },
.info = std::visit(overloaded {
[&](const TextHash & th) -> ContentAddressWithReferences {
assert(references.count(path) == 0);
return TextInfo {
th,
.references = references,
};
},
[&](const FixedOutputHash & foh) -> ContentAddressWithReferences {
auto refs = references;
bool hasSelfReference = false;
if (refs.count(path)) {
hasSelfReference = true;
refs.erase(path);
}
return FixedOutputInfo {
foh,
.references = {
.others = std::move(refs),
.self = hasSelfReference,
},
};
},
}, *ca),
};
return std::visit(overloaded {
[&](const TextHash & th) -> ContentAddressWithReferences {
assert(references.count(path) == 0);
return TextInfo {
th,
.references = references,
};
},
[&](const FixedOutputHash & foh) -> ContentAddressWithReferences {
auto refs = references;
bool hasSelfReference = false;
if (refs.count(path)) {
hasSelfReference = true;
refs.erase(path);
}
return FixedOutputInfo {
foh,
.references = {
.others = std::move(refs),
.self = hasSelfReference,
},
};
},
}, *ca);
}
bool ValidPathInfo::isContentAddressed(const Store & store) const
{
auto fullCaOpt = fullStorePathDescriptorOpt();
auto fullCaOpt = contentAddressWithReferenences();
if (! fullCaOpt)
return false;
auto caPath = store.makeFixedOutputPathFromCA(*fullCaOpt);
auto caPath = store.makeFixedOutputPathFromCA(path.name(), *fullCaOpt);
bool res = caPath == path;
@ -102,9 +99,10 @@ Strings ValidPathInfo::shortRefs() const
ValidPathInfo::ValidPathInfo(
const Store & store,
StorePathDescriptor && info,
std::string_view name,
ContentAddressWithReferences && ca,
Hash narHash)
: path(store.makeFixedOutputPathFromCA(info))
: path(store.makeFixedOutputPathFromCA(name, ca))
, narHash(narHash)
{
std::visit(overloaded {
@ -118,7 +116,7 @@ ValidPathInfo::ValidPathInfo(
this->references.insert(path);
this->ca = std::move((FixedOutputHash &&) foi);
},
}, std::move(info.info));
}, std::move(ca));
}

View file

@ -77,7 +77,7 @@ struct ValidPathInfo
void sign(const Store & store, const SecretKey & secretKey);
std::optional<StorePathDescriptor> fullStorePathDescriptorOpt() const;
std::optional<ContentAddressWithReferences> contentAddressWithReferenences() const;
/* Return true iff the path is verifiably content-addressed. */
bool isContentAddressed(const Store & store) const;
@ -100,7 +100,7 @@ struct ValidPathInfo
ValidPathInfo(const StorePath & path, Hash narHash) : path(path), narHash(narHash) { };
ValidPathInfo(const Store & store,
StorePathDescriptor && ca, Hash narHash);
std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
virtual ~ValidPathInfo() { }

View file

@ -209,17 +209,17 @@ StorePath Store::makeTextPath(std::string_view name, const TextInfo & info) cons
}
StorePath Store::makeFixedOutputPathFromCA(const StorePathDescriptor & desc) const
StorePath Store::makeFixedOutputPathFromCA(std::string_view name, const ContentAddressWithReferences & ca) const
{
// New template
return std::visit(overloaded {
[&](const TextInfo & ti) {
return makeTextPath(desc.name, ti);
return makeTextPath(name, ti);
},
[&](const FixedOutputInfo & foi) {
return makeFixedOutputPath(desc.name, foi);
return makeFixedOutputPath(name, foi);
}
}, desc.info);
}, ca);
}
@ -437,15 +437,13 @@ ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
ValidPathInfo info {
*this,
StorePathDescriptor {
std::string { name },
FixedOutputInfo {
{
.method = method,
.hash = hash,
},
.references = {},
name,
FixedOutputInfo {
{
.method = method,
.hash = hash,
},
.references = {},
},
narHash,
};
@ -997,7 +995,8 @@ void copyStorePath(
if (info->ca && info->references.empty()) {
auto info2 = make_ref<ValidPathInfo>(*info);
info2->path = dstStore.makeFixedOutputPathFromCA(
info->fullStorePathDescriptorOpt().value());
info->path.name(),
info->contentAddressWithReferenences().value());
if (dstStore.storeDir == srcStore.storeDir)
assert(info->path == info2->path);
info = info2;
@ -1110,7 +1109,8 @@ std::map<StorePath, StorePath> copyPaths(
auto storePathForDst = storePathForSrc;
if (currentPathInfo.ca && currentPathInfo.references.empty()) {
storePathForDst = dstStore.makeFixedOutputPathFromCA(
currentPathInfo.fullStorePathDescriptorOpt().value());
currentPathInfo.path.name(),
currentPathInfo.contentAddressWithReferenences().value());
if (dstStore.storeDir == srcStore.storeDir)
assert(storePathForDst == storePathForSrc);
if (storePathForDst != storePathForSrc)

View file

@ -216,7 +216,7 @@ public:
StorePath makeTextPath(std::string_view name, const TextInfo & info) const;
StorePath makeFixedOutputPathFromCA(const StorePathDescriptor & info) const;
StorePath makeFixedOutputPathFromCA(std::string_view name, const ContentAddressWithReferences & ca) const;
/* This is the preparatory part of addToStore(); it computes the
store path to which srcPath is to be copied. Returns the store

View file

@ -43,15 +43,13 @@ struct CmdAddToStore : MixDryRun, StoreCommand
ValidPathInfo info {
*store,
StorePathDescriptor {
.name = *namePart,
.info = FixedOutputInfo {
{
.method = std::move(ingestionMethod),
.hash = std::move(hash),
},
.references = {},
std::move(*namePart),
FixedOutputInfo {
{
.method = std::move(ingestionMethod),
.hash = std::move(hash),
},
.references = {},
},
narHash,
};

View file

@ -200,17 +200,15 @@ struct ProfileManifest
ValidPathInfo info {
*store,
StorePathDescriptor {
"profile",
FixedOutputInfo {
{
.method = FileIngestionMethod::Recursive,
.hash = narHash,
},
.references = {
.others = std::move(references),
.self = false,
},
"profile",
FixedOutputInfo {
{
.method = FileIngestionMethod::Recursive,
.hash = narHash,
},
.references = {
.others = std::move(references),
.self = false,
},
},
narHash,