Skip to content

Commit e7453a4

Browse files
committed
Cleanup
1 parent 62e4faf commit e7453a4

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/libstore/daemon.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,9 @@ static void performOp(
434434
bool repairBool;
435435
conn.from >> repairBool;
436436
auto repair = RepairFlag{repairBool};
437-
std::shared_ptr<const Provenance> provenance;
438-
if (conn.features.contains(WorkerProto::featureProvenance)) {
439-
auto s = readString(conn.from);
440-
if (!s.empty())
441-
provenance = Provenance::from_json_str(s);
442-
}
437+
auto provenance = conn.features.contains(WorkerProto::featureProvenance)
438+
? Provenance::from_json_str_optional(readString(conn.from))
439+
: nullptr;
443440

444441
logger->startWork();
445442
auto pathInfo = [&]() {
@@ -920,11 +917,9 @@ static void performOp(
920917
conn.from >> info.registrationTime >> info.narSize >> info.ultimate;
921918
info.sigs = readStrings<StringSet>(conn.from);
922919
info.ca = ContentAddress::parseOpt(readString(conn.from));
923-
if (conn.features.contains(WorkerProto::featureProvenance)) {
924-
auto s = readString(conn.from);
925-
if (!s.empty())
926-
info.provenance = Provenance::from_json_str(s);
927-
}
920+
info.provenance = conn.features.contains(WorkerProto::featureProvenance)
921+
? Provenance::from_json_str_optional(readString(conn.from))
922+
: nullptr;
928923
conn.from >> repair >> dontCheckSigs;
929924
if (!trusted && dontCheckSigs)
930925
dontCheckSigs = false;

src/libstore/worker-protocol.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,8 @@ UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const St
304304
info.sigs = readStrings<StringSet>(conn.from);
305305
info.ca = ContentAddress::parseOpt(readString(conn.from));
306306
}
307-
if (conn.provenance) {
308-
auto s = readString(conn.from);
309-
if (!s.empty())
310-
info.provenance = Provenance::from_json_str(s);
311-
}
307+
if (conn.provenance)
308+
info.provenance = Provenance::from_json_str_optional(readString(conn.from));
312309
return info;
313310
}
314311

src/libutil/include/nix/util/provenance.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct Provenance
1313
{
1414
static ref<const Provenance> from_json_str(std::string_view);
1515

16+
static std::shared_ptr<const Provenance> from_json_str_optional(std::string_view);
17+
1618
static ref<const Provenance> from_json(const nlohmann::json & json);
1719

1820
std::string to_json_str() const;

src/libutil/provenance.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ ref<const Provenance> Provenance::from_json_str(std::string_view s)
2929
return from_json(nlohmann::json::parse(s));
3030
}
3131

32+
std::shared_ptr<const Provenance> Provenance::from_json_str_optional(std::string_view s)
33+
{
34+
if (s.empty())
35+
return nullptr;
36+
return Provenance::from_json_str(s);
37+
}
38+
3239
ref<const Provenance> Provenance::from_json(const nlohmann::json & json)
3340
{
3441
auto & obj = getObject(json);

0 commit comments

Comments
 (0)