mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Merge 4fb4afa5b0
into f9afc1e68c
This commit is contained in:
commit
fbee3265b7
3 changed files with 10 additions and 10 deletions
|
@ -142,14 +142,14 @@ static void parseContents(CreateRegularFileSink & sink, Source & source)
|
||||||
sink.preallocateContents(size);
|
sink.preallocateContents(size);
|
||||||
|
|
||||||
uint64_t left = size;
|
uint64_t left = size;
|
||||||
std::array<char, 65536> buf;
|
auto buf = std::make_unique<std::array<char, 65536>>();
|
||||||
|
|
||||||
while (left) {
|
while (left) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
auto n = buf.size();
|
auto n = buf->size();
|
||||||
if ((uint64_t)n > left) n = left;
|
if ((uint64_t)n > left) n = left;
|
||||||
source(buf.data(), n);
|
source(buf->data(), n);
|
||||||
sink({buf.data(), n});
|
sink({buf->data(), n});
|
||||||
left -= n;
|
left -= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -340,13 +340,13 @@ void writeFile(const Path & path, Source & source, mode_t mode, bool sync)
|
||||||
if (!fd)
|
if (!fd)
|
||||||
throw SysError("opening file '%1%'", path);
|
throw SysError("opening file '%1%'", path);
|
||||||
|
|
||||||
std::array<char, 64 * 1024> buf;
|
auto buf = std::make_unique<std::array<char, 64 * 1024>>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
auto n = source.read(buf.data(), buf.size());
|
auto n = source.read(buf->data(), buf->size());
|
||||||
writeFull(fd.get(), {buf.data(), n});
|
writeFull(fd.get(), {buf->data(), n});
|
||||||
} catch (EndOfFile &) { break; }
|
} catch (EndOfFile &) { break; }
|
||||||
}
|
}
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|
|
@ -64,10 +64,10 @@ void PosixSourceAccessor::readFile(
|
||||||
|
|
||||||
off_t left = st.st_size;
|
off_t left = st.st_size;
|
||||||
|
|
||||||
std::array<unsigned char, 64 * 1024> buf;
|
auto buf = std::make_unique<std::array<unsigned char, 64 * 1024>>();
|
||||||
while (left) {
|
while (left) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
ssize_t rd = read(fromDescriptorReadOnly(fd.get()), buf.data(), (size_t) std::min(left, (off_t) buf.size()));
|
ssize_t rd = read(fromDescriptorReadOnly(fd.get()), buf->data(), (size_t) std::min(left, (off_t) buf->size()));
|
||||||
if (rd == -1) {
|
if (rd == -1) {
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
throw SysError("reading from file '%s'", showPath(path));
|
throw SysError("reading from file '%s'", showPath(path));
|
||||||
|
@ -76,7 +76,7 @@ void PosixSourceAccessor::readFile(
|
||||||
throw SysError("unexpected end-of-file reading '%s'", showPath(path));
|
throw SysError("unexpected end-of-file reading '%s'", showPath(path));
|
||||||
else {
|
else {
|
||||||
assert(rd <= left);
|
assert(rd <= left);
|
||||||
sink({(char *) buf.data(), (size_t) rd});
|
sink({(char *) buf->data(), (size_t) rd});
|
||||||
left -= rd;
|
left -= rd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue