mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 14:36:16 +02:00
RemoteStore::addToStore(): Send NAR rather than string containing NAR
This allows the NAR to be streamed in the future (though we're not doing that yet).
This commit is contained in:
parent
374908726b
commit
f61f67ddee
5 changed files with 21 additions and 37 deletions
|
@ -61,27 +61,6 @@ void Store::exportPath(const Path & path, Sink & sink)
|
||||||
hashAndWriteSink << exportMagic << path << info->references << info->deriver << 0;
|
hashAndWriteSink << exportMagic << path << info->references << info->deriver << 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TeeSource : Source
|
|
||||||
{
|
|
||||||
Source & readSource;
|
|
||||||
ref<std::string> data;
|
|
||||||
TeeSource(Source & readSource)
|
|
||||||
: readSource(readSource)
|
|
||||||
, data(make_ref<std::string>())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
size_t read(unsigned char * data, size_t len)
|
|
||||||
{
|
|
||||||
size_t n = readSource.read(data, len);
|
|
||||||
this->data->append((char *) data, n);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct NopSink : ParseSink
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
Paths Store::importPaths(Source & source, std::shared_ptr<FSAccessor> accessor, bool dontCheckSigs)
|
Paths Store::importPaths(Source & source, std::shared_ptr<FSAccessor> accessor, bool dontCheckSigs)
|
||||||
{
|
{
|
||||||
Paths res;
|
Paths res;
|
||||||
|
@ -92,7 +71,7 @@ Paths Store::importPaths(Source & source, std::shared_ptr<FSAccessor> accessor,
|
||||||
|
|
||||||
/* Extract the NAR from the source. */
|
/* Extract the NAR from the source. */
|
||||||
TeeSource tee(source);
|
TeeSource tee(source);
|
||||||
NopSink sink;
|
ParseSink sink;
|
||||||
parseDump(sink, tee);
|
parseDump(sink, tee);
|
||||||
|
|
||||||
uint32_t magic = readInt(source);
|
uint32_t magic = readInt(source);
|
||||||
|
|
|
@ -169,9 +169,9 @@ struct LegacySSHStore : public Store
|
||||||
|
|
||||||
/* FIXME: inefficient. */
|
/* FIXME: inefficient. */
|
||||||
ParseSink parseSink; /* null sink; just parse the NAR */
|
ParseSink parseSink; /* null sink; just parse the NAR */
|
||||||
SavingSourceAdapter savedNAR(conn->from);
|
TeeSource savedNAR(conn->from);
|
||||||
parseDump(parseSink, savedNAR);
|
parseDump(parseSink, savedNAR);
|
||||||
sink(savedNAR.s);
|
sink(*savedNAR.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsupported methods. */
|
/* Unsupported methods. */
|
||||||
|
|
|
@ -378,8 +378,9 @@ void RemoteStore::addToStore(const ValidPathInfo & info, const ref<std::string>
|
||||||
conn->to << wopAddToStoreNar
|
conn->to << wopAddToStoreNar
|
||||||
<< info.path << info.deriver << printHash(info.narHash)
|
<< info.path << info.deriver << printHash(info.narHash)
|
||||||
<< info.references << info.registrationTime << info.narSize
|
<< info.references << info.registrationTime << info.narSize
|
||||||
<< info.ultimate << info.sigs << info.ca << *nar << repair << dontCheckSigs;
|
<< info.ultimate << info.sigs << info.ca
|
||||||
// FIXME: don't send nar as a string
|
<< repair << dontCheckSigs;
|
||||||
|
conn->to(*nar);
|
||||||
conn->processStderr();
|
conn->processStderr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,15 +140,16 @@ struct StringSource : Source
|
||||||
|
|
||||||
|
|
||||||
/* Adapter class of a Source that saves all data read to `s'. */
|
/* Adapter class of a Source that saves all data read to `s'. */
|
||||||
struct SavingSourceAdapter : Source
|
struct TeeSource : Source
|
||||||
{
|
{
|
||||||
Source & orig;
|
Source & orig;
|
||||||
string s;
|
ref<std::string> data;
|
||||||
SavingSourceAdapter(Source & orig) : orig(orig) { }
|
TeeSource(Source & orig)
|
||||||
|
: orig(orig), data(make_ref<std::string>()) { }
|
||||||
size_t read(unsigned char * data, size_t len)
|
size_t read(unsigned char * data, size_t len)
|
||||||
{
|
{
|
||||||
size_t n = orig.read(data, len);
|
size_t n = orig.read(data, len);
|
||||||
s.append((const char *) data, n);
|
this->data->append((const char *) data, n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -283,7 +283,7 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
|
||||||
}
|
}
|
||||||
HashType hashAlgo = parseHashType(s);
|
HashType hashAlgo = parseHashType(s);
|
||||||
|
|
||||||
SavingSourceAdapter savedNAR(from);
|
TeeSource savedNAR(from);
|
||||||
RetrieveRegularNARSink savedRegular;
|
RetrieveRegularNARSink savedRegular;
|
||||||
|
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
|
@ -297,7 +297,7 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
|
||||||
|
|
||||||
startWork();
|
startWork();
|
||||||
if (!savedRegular.regular) throw Error("regular file expected");
|
if (!savedRegular.regular) throw Error("regular file expected");
|
||||||
Path path = store->addToStoreFromDump(recursive ? savedNAR.s : savedRegular.s, baseName, recursive, hashAlgo);
|
Path path = store->addToStoreFromDump(recursive ? *savedNAR.data : savedRegular.s, baseName, recursive, hashAlgo);
|
||||||
stopWork();
|
stopWork();
|
||||||
|
|
||||||
to << path;
|
to << path;
|
||||||
|
@ -569,6 +569,7 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
|
||||||
}
|
}
|
||||||
|
|
||||||
case wopAddToStoreNar: {
|
case wopAddToStoreNar: {
|
||||||
|
bool repair, dontCheckSigs;
|
||||||
ValidPathInfo info;
|
ValidPathInfo info;
|
||||||
info.path = readStorePath(*store, from);
|
info.path = readStorePath(*store, from);
|
||||||
from >> info.deriver;
|
from >> info.deriver;
|
||||||
|
@ -578,14 +579,16 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
|
||||||
info.references = readStorePaths<PathSet>(*store, from);
|
info.references = readStorePaths<PathSet>(*store, from);
|
||||||
from >> info.registrationTime >> info.narSize >> info.ultimate;
|
from >> info.registrationTime >> info.narSize >> info.ultimate;
|
||||||
info.sigs = readStrings<StringSet>(from);
|
info.sigs = readStrings<StringSet>(from);
|
||||||
from >> info.ca;
|
from >> info.ca >> repair >> dontCheckSigs;
|
||||||
auto nar = make_ref<std::string>(readString(from));
|
|
||||||
bool repair, dontCheckSigs;
|
|
||||||
from >> repair >> dontCheckSigs;
|
|
||||||
if (!trusted && dontCheckSigs)
|
if (!trusted && dontCheckSigs)
|
||||||
dontCheckSigs = false;
|
dontCheckSigs = false;
|
||||||
|
|
||||||
|
TeeSource tee(from);
|
||||||
|
ParseSink sink;
|
||||||
|
parseDump(sink, tee);
|
||||||
|
|
||||||
startWork();
|
startWork();
|
||||||
store->addToStore(info, nar, repair, dontCheckSigs, nullptr);
|
store->addToStore(info, tee.data, repair, dontCheckSigs, nullptr);
|
||||||
stopWork();
|
stopWork();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue