Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ DownloadFileResult downloadFile(
StringSink sink;
dumpString(res.data, sink);
auto hash = hashString(HashAlgorithm::SHA256, res.data);
ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
*store,
name,
FixedOutputInfo{
.method = FileIngestionMethod::Flat,
.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);
Expand Down
5 changes: 2 additions & 3 deletions src/libstore-tests/nar-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions src/libstore-tests/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions src/libstore-tests/serve-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ VERSIONED_CHARACTERIZATION_TEST(
info;
}),
({
ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
store,
"foo",
FixedOutputInfo{
Expand All @@ -291,8 +291,7 @@ VERSIONED_CHARACTERIZATION_TEST(
.self = true,
},
},
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
};
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="));
info.deriver = StorePath{
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
};
Expand Down
5 changes: 2 additions & 3 deletions src/libstore-tests/worker-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ VERSIONED_CHARACTERIZATION_TEST(
info;
}),
({
ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
store,
"foo",
FixedOutputInfo{
Expand All @@ -532,8 +532,7 @@ VERSIONED_CHARACTERIZATION_TEST(
.self = true,
},
},
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
};
Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="));
info.registrationTime = 23423;
info.narSize = 34878;
info;
Expand Down
10 changes: 4 additions & 6 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ StorePath BinaryCacheStore::addToStoreFromDump(
repair,
CheckSigs,
[&](HashResult nar) {
ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
*this,
name,
ContentAddressWithReferences::fromParts(
Expand All @@ -378,8 +378,7 @@ StorePath BinaryCacheStore::addToStoreFromDump(
// without modulus
.self = false,
}),
nar.hash,
};
nar.hash);
info.narSize = nar.numBytesDigested;
return info;
})
Expand Down Expand Up @@ -484,7 +483,7 @@ StorePath BinaryCacheStore::addToStore(
repair,
CheckSigs,
[&](HashResult nar) {
ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
*this,
name,
ContentAddressWithReferences::fromParts(
Expand All @@ -496,8 +495,7 @@ StorePath BinaryCacheStore::addToStore(
// without modulus
.self = false,
}),
nar.hash,
};
nar.hash);
info.narSize = nar.numBytesDigested;
return info;
})
Expand Down
11 changes: 6 additions & 5 deletions src/libstore/include/nix/store/nar-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/include/nix/store/path-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/libstore/make-content-addressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ std::map<StorePath, StorePath> makeContentAddressed(Store & srcStore, Store & ds

auto narModuloHash = hashModuloSink.finish().hash;

ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
dstStore,
path.name(),
FixedOutputInfo{
.method = FileIngestionMethod::NixArchive,
.hash = narModuloHash,
.references = std::move(refs),
},
Hash::dummy,
};
Hash::dummy);

printInfo("rewriting '%s' to '%s'", pathS, dstStore.printStorePath(info.path));

Expand Down
22 changes: 13 additions & 9 deletions src/libstore/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -279,8 +279,7 @@ ValidPathInfo Store::addToStoreSlow(
.others = references,
.self = false,
}),
narHash,
};
narHash);
info.narSize = narSize;

if (!isValidPath(info.path)) {
Expand Down
5 changes: 2 additions & 3 deletions src/libstore/unix/build/derivation-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/nix/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct ProfileManifest

auto narHash = hashString(HashAlgorithm::SHA256, sink.s);

ValidPathInfo info{
auto info = ValidPathInfo::makeFromCA(
*store,
"profile",
FixedOutputInfo{
Expand All @@ -270,8 +270,7 @@ struct ProfileManifest
.self = false,
},
},
narHash,
};
narHash);
info.narSize = sink.s.size();

StringSource source(sink.s);
Expand Down
Loading