forked from lix-project/lix
libstore: turn copyNAR into a generator
Change-Id: Id452f6a03faa1037ff13af0f63e32883966ff40d
This commit is contained in:
parent
03db4efab9
commit
a5d431a911
|
@ -463,7 +463,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||||
command. (We don't trust `addToStoreFromDump` to not
|
command. (We don't trust `addToStoreFromDump` to not
|
||||||
eagerly consume the entire stream it's given, past the
|
eagerly consume the entire stream it's given, past the
|
||||||
length of the Nar. */
|
length of the Nar. */
|
||||||
copyNAR(from, saved);
|
saved << copyNAR(from);
|
||||||
} else {
|
} else {
|
||||||
/* Incrementally parse the NAR file, stripping the
|
/* Incrementally parse the NAR file, stripping the
|
||||||
metadata, and streaming the sole file we expect into
|
metadata, and streaming the sole file we expect into
|
||||||
|
@ -884,7 +884,6 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||||
|
|
||||||
else {
|
else {
|
||||||
std::unique_ptr<Source> source;
|
std::unique_ptr<Source> source;
|
||||||
StringSink saved;
|
|
||||||
source = std::make_unique<TunnelSource>(from, to);
|
source = std::make_unique<TunnelSource>(from, to);
|
||||||
|
|
||||||
logger->startWork();
|
logger->startWork();
|
||||||
|
|
|
@ -64,7 +64,7 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
||||||
|
|
||||||
/* Extract the NAR from the source. */
|
/* Extract the NAR from the source. */
|
||||||
StringSink saved;
|
StringSink saved;
|
||||||
copyNAR(source, saved);
|
saved << copyNAR(source);
|
||||||
|
|
||||||
uint32_t magic = readInt(source);
|
uint32_t magic = readInt(source);
|
||||||
if (magic != exportMagic)
|
if (magic != exportMagic)
|
||||||
|
|
|
@ -193,7 +193,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
||||||
<< info.sigs
|
<< info.sigs
|
||||||
<< renderContentAddress(info.ca);
|
<< renderContentAddress(info.ca);
|
||||||
try {
|
try {
|
||||||
copyNAR(source, conn->to);
|
conn->to << copyNAR(source);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
conn->good = false;
|
conn->good = false;
|
||||||
throw;
|
throw;
|
||||||
|
@ -206,7 +206,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
||||||
<< ServeProto::Command::ImportPaths
|
<< ServeProto::Command::ImportPaths
|
||||||
<< 1;
|
<< 1;
|
||||||
try {
|
try {
|
||||||
copyNAR(source, conn->to);
|
conn->to << copyNAR(source);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
conn->good = false;
|
conn->good = false;
|
||||||
throw;
|
throw;
|
||||||
|
@ -233,7 +233,7 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
||||||
|
|
||||||
conn->to << ServeProto::Command::DumpStorePath << printStorePath(path);
|
conn->to << ServeProto::Command::DumpStorePath << printStorePath(path);
|
||||||
conn->to.flush();
|
conn->to.flush();
|
||||||
copyNAR(conn->from, sink);
|
sink << copyNAR(conn->from);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
|
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
|
||||||
|
|
|
@ -469,7 +469,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 23) {
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 23) {
|
||||||
conn.withFramedSink([&](Sink & sink) {
|
conn.withFramedSink([&](Sink & sink) {
|
||||||
copyNAR(source, sink);
|
sink << copyNAR(source);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
conn.processStderr(0, &source);
|
conn.processStderr(0, &source);
|
||||||
|
@ -853,7 +853,7 @@ void RemoteStore::narFromPath(const StorePath & path, Sink & sink)
|
||||||
auto conn(connections->get());
|
auto conn(connections->get());
|
||||||
conn->to << WorkerProto::Op::NarFromPath << printStorePath(path);
|
conn->to << WorkerProto::Op::NarFromPath << printStorePath(path);
|
||||||
conn->processStderr();
|
conn->processStderr();
|
||||||
copyNAR(conn->from, sink);
|
sink << copyNAR(conn->from);
|
||||||
}
|
}
|
||||||
|
|
||||||
ref<FSAccessor> RemoteStore::getFSAccessor()
|
ref<FSAccessor> RemoteStore::getFSAccessor()
|
||||||
|
|
|
@ -413,16 +413,14 @@ void restorePath(const Path & path, Source & source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void copyNAR(Source & source, Sink & sink)
|
WireFormatGenerator copyNAR(Source & source)
|
||||||
{
|
{
|
||||||
// FIXME: if 'source' is the output of dumpPath() followed by EOF,
|
// FIXME: if 'source' is the output of dumpPath() followed by EOF,
|
||||||
// we should just forward all data directly without parsing.
|
// we should just forward all data directly without parsing.
|
||||||
|
|
||||||
ParseSink parseSink; /* null sink; just parse the NAR */
|
static ParseSink parseSink; /* null sink; just parse the NAR */
|
||||||
|
|
||||||
TeeSource wrapper { source, sink };
|
return parseAndCopyDump(parseSink, source);
|
||||||
|
|
||||||
parseDump(parseSink, wrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,9 +122,9 @@ void parseDump(ParseSink & sink, Source & source);
|
||||||
void restorePath(const Path & path, Source & source);
|
void restorePath(const Path & path, Source & source);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a NAR from 'source' and write it to 'sink'.
|
* Read a NAR from 'source' and return it as a generator.
|
||||||
*/
|
*/
|
||||||
void copyNAR(Source & source, Sink & sink);
|
WireFormatGenerator copyNAR(Source & source);
|
||||||
|
|
||||||
|
|
||||||
inline constexpr std::string_view narVersionMagic1 = "nix-archive-1";
|
inline constexpr std::string_view narVersionMagic1 = "nix-archive-1";
|
||||||
|
|
Loading…
Reference in a new issue