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); auto hash = hashString(htSHA256, res.data);
ValidPathInfo info { ValidPathInfo info {
*store, *store,
{ name,
.name = name, FixedOutputInfo {
.info = FixedOutputInfo { {
{ .method = FileIngestionMethod::Flat,
.method = FileIngestionMethod::Flat, .hash = hash,
.hash = hash,
},
.references = {},
}, },
.references = {},
}, },
hashString(htSHA256, sink.s), 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) { return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info { ValidPathInfo info {
*this, *this,
{ name,
.name = std::string { name }, FixedOutputInfo {
.info = FixedOutputInfo { {
{ .method = method,
.method = method, .hash = nar.first,
.hash = nar.first, },
}, .references = {
.references = { .others = references,
.others = references, .self = false,
.self = false,
},
}, },
}, },
nar.first, nar.first,
@ -427,17 +425,15 @@ StorePath BinaryCacheStore::addToStore(
return addToStoreCommon(*source, repair, CheckSigs, [&](HashResult nar) { return addToStoreCommon(*source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info { ValidPathInfo info {
*this, *this,
{ name,
.name = std::string { name }, FixedOutputInfo {
.info = FixedOutputInfo { {
{ .method = method,
.method = method, .hash = h,
.hash = h, },
}, .references = {
.references = { .others = references,
.others = references, .self = false,
.self = false,
},
}, },
}, },
nar.first, nar.first,
@ -465,12 +461,10 @@ StorePath BinaryCacheStore::addTextToStore(
return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) { return addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) {
ValidPathInfo info { ValidPathInfo info {
*this, *this,
{ std::string { name },
.name = std::string { name }, TextInfo {
.info = TextInfo { { .hash = textHash },
{ .hash = textHash }, references,
references,
},
}, },
nar.first, nar.first,
}; };

View file

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

View file

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

View file

@ -132,11 +132,4 @@ typedef std::variant<
ContentAddressWithReferences caWithoutRefs(const ContentAddress &); 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. // Recompute store path so that we can use a different store root.
if (path.second) { if (path.second) {
subPath = makeFixedOutputPathFromCA({ subPath = makeFixedOutputPathFromCA(
.name = std::string { path.first.name() }, path.first.name(),
.info = caWithoutRefs(*path.second), caWithoutRefs(*path.second));
});
if (sub->storeDir == storeDir) if (sub->storeDir == storeDir)
assert(subPath == path.first); assert(subPath == path.first);
if (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 [hash, size] = hashSink->finish();
auto desc = StorePathDescriptor { ContentAddressWithReferences desc = FixedOutputInfo {
std::string { name }, {
FixedOutputInfo { .method = method,
{ .hash = hash,
.method = method, },
.hash = hash, .references = {
}, .others = references,
.references = { .self = false,
.others = references,
.self = false,
},
}, },
}; };
auto dstPath = makeFixedOutputPathFromCA(desc); auto dstPath = makeFixedOutputPathFromCA(name, desc);
addTempRoot(dstPath); addTempRoot(dstPath);
@ -1475,7 +1471,12 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
optimisePath(realPath, repair); optimisePath(realPath, repair);
ValidPathInfo info { *this, std::move(desc), narHash.first }; ValidPathInfo info {
*this,
name,
std::move(desc),
narHash.first
};
info.narSize = narHash.second; info.narSize = narHash.second;
registerValidPath(info); registerValidPath(info);
} }

View file

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

View file

@ -16,8 +16,8 @@ struct NarInfo : ValidPathInfo
uint64_t fileSize = 0; uint64_t fileSize = 0;
NarInfo() = delete; NarInfo() = delete;
NarInfo(const Store & store, StorePathDescriptor && ca, Hash narHash) NarInfo(const Store & store, std::string && name, ContentAddressWithReferences && ca, Hash narHash)
: ValidPathInfo(store, std::move(ca), narHash) : ValidPathInfo(store, std::move(name), std::move(ca), narHash)
{ } { }
NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { } NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
NarInfo(const ValidPathInfo & info) : ValidPathInfo(info) { } 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))); sigs.insert(secretKey.signDetached(fingerprint(store)));
} }
std::optional<StorePathDescriptor> ValidPathInfo::fullStorePathDescriptorOpt() const std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithReferenences() const
{ {
if (! ca) if (! ca)
return std::nullopt; return std::nullopt;
return StorePathDescriptor { return std::visit(overloaded {
.name = std::string { path.name() }, [&](const TextHash & th) -> ContentAddressWithReferences {
.info = std::visit(overloaded { assert(references.count(path) == 0);
[&](const TextHash & th) -> ContentAddressWithReferences { return TextInfo {
assert(references.count(path) == 0); th,
return TextInfo { .references = references,
th, };
.references = references, },
}; [&](const FixedOutputHash & foh) -> ContentAddressWithReferences {
}, auto refs = references;
[&](const FixedOutputHash & foh) -> ContentAddressWithReferences { bool hasSelfReference = false;
auto refs = references; if (refs.count(path)) {
bool hasSelfReference = false; hasSelfReference = true;
if (refs.count(path)) { refs.erase(path);
hasSelfReference = true; }
refs.erase(path); return FixedOutputInfo {
} foh,
return FixedOutputInfo { .references = {
foh, .others = std::move(refs),
.references = { .self = hasSelfReference,
.others = std::move(refs), },
.self = hasSelfReference, };
}, },
}; }, *ca);
},
}, *ca),
};
} }
bool ValidPathInfo::isContentAddressed(const Store & store) const bool ValidPathInfo::isContentAddressed(const Store & store) const
{ {
auto fullCaOpt = fullStorePathDescriptorOpt(); auto fullCaOpt = contentAddressWithReferenences();
if (! fullCaOpt) if (! fullCaOpt)
return false; return false;
auto caPath = store.makeFixedOutputPathFromCA(*fullCaOpt); auto caPath = store.makeFixedOutputPathFromCA(path.name(), *fullCaOpt);
bool res = caPath == path; bool res = caPath == path;
@ -102,9 +99,10 @@ Strings ValidPathInfo::shortRefs() const
ValidPathInfo::ValidPathInfo( ValidPathInfo::ValidPathInfo(
const Store & store, const Store & store,
StorePathDescriptor && info, std::string_view name,
ContentAddressWithReferences && ca,
Hash narHash) Hash narHash)
: path(store.makeFixedOutputPathFromCA(info)) : path(store.makeFixedOutputPathFromCA(name, ca))
, narHash(narHash) , narHash(narHash)
{ {
std::visit(overloaded { std::visit(overloaded {
@ -118,7 +116,7 @@ ValidPathInfo::ValidPathInfo(
this->references.insert(path); this->references.insert(path);
this->ca = std::move((FixedOutputHash &&) foi); 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); 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. */ /* Return true iff the path is verifiably content-addressed. */
bool isContentAddressed(const Store & store) const; bool isContentAddressed(const Store & store) const;
@ -100,7 +100,7 @@ struct ValidPathInfo
ValidPathInfo(const StorePath & path, Hash narHash) : path(path), narHash(narHash) { }; ValidPathInfo(const StorePath & path, Hash narHash) : path(path), narHash(narHash) { };
ValidPathInfo(const Store & store, ValidPathInfo(const Store & store,
StorePathDescriptor && ca, Hash narHash); std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
virtual ~ValidPathInfo() { } 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 // New template
return std::visit(overloaded { return std::visit(overloaded {
[&](const TextInfo & ti) { [&](const TextInfo & ti) {
return makeTextPath(desc.name, ti); return makeTextPath(name, ti);
}, },
[&](const FixedOutputInfo & foi) { [&](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 { ValidPathInfo info {
*this, *this,
StorePathDescriptor { name,
std::string { name }, FixedOutputInfo {
FixedOutputInfo { {
{ .method = method,
.method = method, .hash = hash,
.hash = hash,
},
.references = {},
}, },
.references = {},
}, },
narHash, narHash,
}; };
@ -997,7 +995,8 @@ void copyStorePath(
if (info->ca && info->references.empty()) { if (info->ca && info->references.empty()) {
auto info2 = make_ref<ValidPathInfo>(*info); auto info2 = make_ref<ValidPathInfo>(*info);
info2->path = dstStore.makeFixedOutputPathFromCA( info2->path = dstStore.makeFixedOutputPathFromCA(
info->fullStorePathDescriptorOpt().value()); info->path.name(),
info->contentAddressWithReferenences().value());
if (dstStore.storeDir == srcStore.storeDir) if (dstStore.storeDir == srcStore.storeDir)
assert(info->path == info2->path); assert(info->path == info2->path);
info = info2; info = info2;
@ -1110,7 +1109,8 @@ std::map<StorePath, StorePath> copyPaths(
auto storePathForDst = storePathForSrc; auto storePathForDst = storePathForSrc;
if (currentPathInfo.ca && currentPathInfo.references.empty()) { if (currentPathInfo.ca && currentPathInfo.references.empty()) {
storePathForDst = dstStore.makeFixedOutputPathFromCA( storePathForDst = dstStore.makeFixedOutputPathFromCA(
currentPathInfo.fullStorePathDescriptorOpt().value()); currentPathInfo.path.name(),
currentPathInfo.contentAddressWithReferenences().value());
if (dstStore.storeDir == srcStore.storeDir) if (dstStore.storeDir == srcStore.storeDir)
assert(storePathForDst == storePathForSrc); assert(storePathForDst == storePathForSrc);
if (storePathForDst != storePathForSrc) if (storePathForDst != storePathForSrc)

View file

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

View file

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

View file

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