Skip to content

Commit

Permalink
Don't add StorePathDescriptor for now
Browse files Browse the repository at this point in the history
We don't need it yet, we can add it back later.
  • Loading branch information
Ericson2314 committed Jan 23, 2023
1 parent c67e0cc commit 4540e7b
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 151 deletions.
14 changes: 6 additions & 8 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
50 changes: 22 additions & 28 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
Expand Down
14 changes: 6 additions & 8 deletions src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
7 changes: 3 additions & 4 deletions src/libstore/build/substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 0 additions & 7 deletions src/libstore/content-address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

}
35 changes: 18 additions & 17 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 6 additions & 8 deletions src/libstore/make-content-addressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/nar-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down
64 changes: 31 additions & 33 deletions src/libstore/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -118,7 +116,7 @@ ValidPathInfo::ValidPathInfo(
this->references.insert(path);
this->ca = std::move((FixedOutputHash &&) foi);
},
}, std::move(info.info));
}, std::move(ca));
}


Expand Down
4 changes: 2 additions & 2 deletions src/libstore/path-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() { }

Expand Down
Loading

0 comments on commit 4540e7b

Please sign in to comment.