mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 16:26:18 +02:00
Revert "LocalStore::addToStoreFromDump copy in chunks"
This reverts commit 592851fb67
. We don't
need this extra feature anymore
This commit is contained in:
parent
bc109648c4
commit
5602637d9e
3 changed files with 15 additions and 31 deletions
|
@ -1037,7 +1037,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
|
|||
FileIngestionMethod method, HashType hashAlgo, PathFilter & filter, RepairFlag repair)
|
||||
{
|
||||
Path srcPath(absPath(_srcPath));
|
||||
auto source = sinkToSource([&](Sink & sink, size_t & wanted) {
|
||||
auto source = sinkToSource([&](Sink & sink) {
|
||||
if (method == FileIngestionMethod::Recursive)
|
||||
dumpPath(srcPath, sink, filter);
|
||||
else
|
||||
|
|
|
@ -165,43 +165,35 @@ size_t StringSource::read(unsigned char * data, size_t len)
|
|||
#endif
|
||||
|
||||
std::unique_ptr<Source> sinkToSource(
|
||||
std::function<void(Sink &, size_t &)> fun,
|
||||
std::function<void(Sink &)> fun,
|
||||
std::function<void()> eof)
|
||||
{
|
||||
struct SinkToSource : Source
|
||||
{
|
||||
typedef boost::coroutines2::coroutine<std::basic_string<uint8_t>> coro_t;
|
||||
typedef boost::coroutines2::coroutine<std::string> coro_t;
|
||||
|
||||
std::function<void(Sink &, size_t &)> fun;
|
||||
std::function<void(Sink &)> fun;
|
||||
std::function<void()> eof;
|
||||
std::optional<coro_t::pull_type> coro;
|
||||
bool started = false;
|
||||
|
||||
/* It would be nicer to have the co-routines have both args and a
|
||||
return value, but unfortunately that was removed from Boost's
|
||||
implementation for some reason, so we use some extra state instead.
|
||||
*/
|
||||
size_t wanted = 0;
|
||||
|
||||
SinkToSource(std::function<void(Sink &, size_t &)> fun, std::function<void()> eof)
|
||||
SinkToSource(std::function<void(Sink &)> fun, std::function<void()> eof)
|
||||
: fun(fun), eof(eof)
|
||||
{
|
||||
}
|
||||
|
||||
std::basic_string<uint8_t> cur;
|
||||
std::string cur;
|
||||
size_t pos = 0;
|
||||
|
||||
size_t read(unsigned char * data, size_t len) override
|
||||
{
|
||||
wanted = len < cur.size() ? 0 : len - cur.size();
|
||||
if (!coro) {
|
||||
if (!coro)
|
||||
coro = coro_t::pull_type([&](coro_t::push_type & yield) {
|
||||
LambdaSink sink([&](const uint8_t * data, size_t len) {
|
||||
if (len) yield(std::basic_string<uint8_t> { data, len });
|
||||
LambdaSink sink([&](const unsigned char * data, size_t len) {
|
||||
if (len) yield(std::string((const char *) data, len));
|
||||
});
|
||||
fun(sink, wanted);
|
||||
fun(sink);
|
||||
});
|
||||
}
|
||||
|
||||
if (!*coro) { eof(); abort(); }
|
||||
|
||||
|
@ -211,10 +203,11 @@ std::unique_ptr<Source> sinkToSource(
|
|||
pos = 0;
|
||||
}
|
||||
|
||||
auto numCopied = cur.copy(data, len, pos);
|
||||
pos += numCopied;
|
||||
auto n = std::min(cur.size() - pos, len);
|
||||
memcpy(data, (unsigned char *) cur.data() + pos, n);
|
||||
pos += n;
|
||||
|
||||
return numCopied;
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -273,19 +273,10 @@ struct ChainSource : Source
|
|||
/* Convert a function that feeds data into a Sink into a Source. The
|
||||
Source executes the function as a coroutine. */
|
||||
std::unique_ptr<Source> sinkToSource(
|
||||
std::function<void(Sink &, size_t &)> fun,
|
||||
std::function<void()> eof = []() {
|
||||
throw EndOfFile("coroutine has finished");
|
||||
});
|
||||
|
||||
static inline std::unique_ptr<Source> sinkToSource(
|
||||
std::function<void(Sink &)> fun,
|
||||
std::function<void()> eof = []() {
|
||||
throw EndOfFile("coroutine has finished");
|
||||
})
|
||||
{
|
||||
return sinkToSource([fun](Sink & s, size_t & _) { fun(s); }, eof);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
void writePadding(size_t len, Sink & sink);
|
||||
|
|
Loading…
Reference in a new issue