Skip to content

Commit 87d1e6f

Browse files
authored
Merge pull request #399 from DeterminateSystems/copy-provenance-daemon
Preserve provenance while copying paths to the daemon
2 parents 962e041 + f0ae44e commit 87d1e6f

8 files changed

Lines changed: 31 additions & 45 deletions

File tree

src/libstore/daemon.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,21 @@ static void performOp(
515515
logger->startWork();
516516
{
517517
FramedSource source(conn.from);
518-
store->addMultipleToStore(source, RepairFlag{repair}, dontCheckSigs ? NoCheckSigs : CheckSigs);
518+
auto expected = readNum<uint64_t>(source);
519+
for (uint64_t i = 0; i < expected; ++i) {
520+
auto info = WorkerProto::Serialise<ValidPathInfo>::read(
521+
*store,
522+
WorkerProto::ReadConn{
523+
.from = source,
524+
.version = conn.protoVersion.features.contains(WorkerProto::featureVersionedAddToStoreMultiple)
525+
? conn.protoVersion
526+
: WorkerProto::Version{.number = {.major = 1, .minor = 16}},
527+
});
528+
info.ultimate = false;
529+
EnsureRead wrapper{source, info.narSize};
530+
store->addToStore(info, wrapper, RepairFlag{repair}, dontCheckSigs ? NoCheckSigs : CheckSigs);
531+
wrapper.finish();
532+
}
519533
}
520534
logger->stopWork();
521535
break;

src/libstore/include/nix/store/remote-store.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ struct RemoteStore : public virtual Store,
103103

104104
void addToStore(const ValidPathInfo & info, Source & nar, RepairFlag repair, CheckSigsFlag checkSigs) override;
105105

106-
void addMultipleToStore(Source & source, RepairFlag repair, CheckSigsFlag checkSigs) override;
107-
108106
void
109107
addMultipleToStore(PathsSource && pathsToCopy, Activity & act, RepairFlag repair, CheckSigsFlag checkSigs) override;
110108

src/libstore/include/nix/store/store-api.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,6 @@ public:
571571
/**
572572
* Import multiple paths into the store.
573573
*/
574-
virtual void addMultipleToStore(Source & source, RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs);
575-
576574
virtual void addMultipleToStore(
577575
PathsSource && pathsToCopy, Activity & act, RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs);
578576

src/libstore/include/nix/store/worker-protocol-connection.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct WorkerProto::BasicConnection
3636
return WorkerProto::ReadConn{
3737
.from = from,
3838
.version = protoVersion,
39-
.provenance = protoVersion.features.contains(WorkerProto::featureProvenance),
4039
};
4140
}
4241

@@ -53,7 +52,6 @@ struct WorkerProto::BasicConnection
5352
return WorkerProto::WriteConn{
5453
.to = to,
5554
.version = protoVersion,
56-
.provenance = protoVersion.features.contains(WorkerProto::featureProvenance),
5755
};
5856
}
5957
};

src/libstore/include/nix/store/worker-protocol.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct WorkerProto
111111

112112
static constexpr std::string_view featureQueryActiveBuilds = "queryActiveBuilds";
113113
static constexpr std::string_view featureProvenance = "provenance";
114+
static constexpr std::string_view featureVersionedAddToStoreMultiple = "versionedAddToStoreMultiple";
114115

115116
/**
116117
* A unidirectional read connection, to be used by the read half of the
@@ -121,7 +122,6 @@ struct WorkerProto
121122
Source & from;
122123
const Version & version;
123124
bool shortStorePaths = false;
124-
bool provenance = false;
125125
};
126126

127127
/**
@@ -133,7 +133,6 @@ struct WorkerProto
133133
Sink & to;
134134
const Version & version;
135135
bool shortStorePaths = false;
136-
bool provenance = false;
137136
};
138137

139138
/**

src/libstore/remote-store.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,13 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, Repair
469469
void RemoteStore::addMultipleToStore(
470470
PathsSource && pathsToCopy, Activity & act, RepairFlag repair, CheckSigsFlag checkSigs)
471471
{
472+
if (getConnection()->protoVersion.number < WorkerProto::Version::Number{1, 32}) {
473+
Store::addMultipleToStore(std::move(pathsToCopy), act, repair, checkSigs);
474+
return;
475+
}
476+
477+
auto conn(getConnection());
478+
472479
// `addMultipleToStore` is single threaded
473480
size_t bytesExpected = 0;
474481
for (auto & [pathInfo, _] : pathsToCopy) {
@@ -489,25 +496,18 @@ void RemoteStore::addMultipleToStore(
489496
*this,
490497
WorkerProto::WriteConn{
491498
.to = sink,
492-
.version = {.number = {.major = 1, .minor = 16}},
499+
.version = conn->protoVersion.features.contains(WorkerProto::featureVersionedAddToStoreMultiple)
500+
? conn->protoVersion
501+
: WorkerProto::Version{.number = {.major = 1, .minor = 16}},
493502
},
494503
pathInfo);
495504
pathSource->drainInto(sink);
496505
pathsToCopy.pop_back();
497506
}
498507
});
499508

500-
addMultipleToStore(*source, repair, checkSigs);
501-
}
502-
503-
void RemoteStore::addMultipleToStore(Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
504-
{
505-
if (getConnection()->protoVersion >= WorkerProto::Version{.number = {1, 32}}) {
506-
auto conn(getConnection());
507-
conn->to << WorkerProto::Op::AddMultipleToStore << repair << !checkSigs;
508-
conn.withFramedSink([&](Sink & sink) { source.drainInto(sink); });
509-
} else
510-
Store::addMultipleToStore(source, repair, checkSigs);
509+
conn->to << WorkerProto::Op::AddMultipleToStore << repair << !checkSigs;
510+
conn.withFramedSink([&](Sink & sink) { source->drainInto(sink); });
511511
}
512512

513513
void RemoteStore::registerDrvOutput(const Realisation & info)

src/libstore/store-api.cc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include "nix/util/callback.hh"
1515
#include "nix/util/git.hh"
1616
#include "nix/util/posix-source-accessor.hh"
17-
// FIXME this should not be here, see TODO below on
18-
// `addMultipleToStore`.
19-
#include "nix/store/worker-protocol.hh"
2017
#include "nix/util/signals.hh"
2118
#include "nix/util/environment-variables.hh"
2219
#include "nix/util/file-system.hh"
@@ -224,25 +221,6 @@ void Store::addMultipleToStore(PathsSource && pathsToCopy, Activity & act, Repai
224221
});
225222
}
226223

227-
void Store::addMultipleToStore(Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
228-
{
229-
auto expected = readNum<uint64_t>(source);
230-
for (uint64_t i = 0; i < expected; ++i) {
231-
// FIXME we should not be using the worker protocol here, let
232-
// alone the worker protocol with a hard-coded version!
233-
auto info = WorkerProto::Serialise<ValidPathInfo>::read(
234-
*this,
235-
WorkerProto::ReadConn{
236-
.from = source,
237-
.version = {.number = {.major = 1, .minor = 16}},
238-
});
239-
info.ultimate = false;
240-
EnsureRead wrapper{source, info.narSize};
241-
addToStore(info, wrapper, repair, checkSigs);
242-
wrapper.finish();
243-
}
244-
}
245-
246224
/*
247225
The aim of this function is to compute in one pass the correct ValidPathInfo for
248226
the files that we are trying to add to the store. To accomplish that in one

src/libstore/worker-protocol.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const WorkerProto::Version WorkerProto::latest = {
2525
{
2626
std::string{WorkerProto::featureQueryActiveBuilds},
2727
std::string{WorkerProto::featureProvenance},
28+
std::string{WorkerProto::featureVersionedAddToStoreMultiple},
2829
},
2930
};
3031

@@ -352,7 +353,7 @@ UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const St
352353
info.sigs = WorkerProto::Serialise<std::set<Signature>>::read(store, conn);
353354
info.ca = ContentAddress::parseOpt(readString(conn.from));
354355
}
355-
if (conn.provenance)
356+
if (conn.version.features.contains(WorkerProto::featureProvenance))
356357
info.provenance = Provenance::from_json_str_optional(readString(conn.from));
357358
return info;
358359
}
@@ -369,7 +370,7 @@ void WorkerProto::Serialise<UnkeyedValidPathInfo>::write(
369370
WorkerProto::write(store, conn, pathInfo.sigs);
370371
conn.to << renderContentAddress(pathInfo.ca);
371372
}
372-
if (conn.provenance)
373+
if (conn.version.features.contains(WorkerProto::featureProvenance))
373374
conn.to << (pathInfo.provenance ? pathInfo.provenance->to_json_str() : "");
374375
}
375376

0 commit comments

Comments
 (0)