forked from lix-project/lix
Merge pull request #3041 from zimbatm/nix-store-error-13
Fix for `unknown serve command 13`
This commit is contained in:
commit
f435634a29
|
@ -179,6 +179,36 @@ struct TeeSource : Source
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* A reader that consumes the original Source until 'size'. */
|
||||||
|
struct SizedSource : Source
|
||||||
|
{
|
||||||
|
Source & orig;
|
||||||
|
size_t remain;
|
||||||
|
SizedSource(Source & orig, size_t size)
|
||||||
|
: orig(orig), remain(size) { }
|
||||||
|
size_t read(unsigned char * data, size_t len)
|
||||||
|
{
|
||||||
|
if (this->remain <= 0) {
|
||||||
|
throw EndOfFile("sized: unexpected end-of-file");
|
||||||
|
}
|
||||||
|
len = std::min(len, this->remain);
|
||||||
|
size_t n = this->orig.read(data, len);
|
||||||
|
this->remain -= n;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Consume the original source until no remain data is left to consume. */
|
||||||
|
size_t drainAll()
|
||||||
|
{
|
||||||
|
std::vector<unsigned char> buf(8192);
|
||||||
|
size_t sum = 0;
|
||||||
|
while (this->remain > 0) {
|
||||||
|
size_t n = read(buf.data(), buf.size());
|
||||||
|
sum += n;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* Convert a function into a sink. */
|
/* Convert a function into a sink. */
|
||||||
struct LambdaSink : Sink
|
struct LambdaSink : Sink
|
||||||
|
|
|
@ -950,8 +950,16 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
info.sigs = readStrings<StringSet>(in);
|
info.sigs = readStrings<StringSet>(in);
|
||||||
in >> info.ca;
|
in >> info.ca;
|
||||||
|
|
||||||
// FIXME: race if addToStore doesn't read source?
|
if (info.narSize == 0) {
|
||||||
store->addToStore(info, in, NoRepair, NoCheckSigs);
|
throw Error("narInfo is too old and missing the narSize field");
|
||||||
|
}
|
||||||
|
|
||||||
|
SizedSource sizedSource(in, info.narSize);
|
||||||
|
|
||||||
|
store->addToStore(info, sizedSource, NoRepair, NoCheckSigs);
|
||||||
|
|
||||||
|
// consume all the data that has been sent before continuing.
|
||||||
|
sizedSource.drainAll();
|
||||||
|
|
||||||
out << 1; // indicate success
|
out << 1; // indicate success
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue