mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 16:26:18 +02:00
parent
636ec17139
commit
87157b2bd3
1 changed files with 16 additions and 6 deletions
|
@ -326,7 +326,12 @@ void writeFile(const Path & path, const string & s, mode_t mode)
|
|||
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
|
||||
if (!fd)
|
||||
throw SysError("opening file '%1%'", path);
|
||||
try {
|
||||
writeFull(fd.get(), s);
|
||||
} catch (Error & e) {
|
||||
e.addTrace({}, "writing file '%1%'", path);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -338,12 +343,17 @@ void writeFile(const Path & path, Source & source, mode_t mode)
|
|||
|
||||
std::vector<unsigned char> buf(64 * 1024);
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
try {
|
||||
auto n = source.read(buf.data(), buf.size());
|
||||
writeFull(fd.get(), (unsigned char *) buf.data(), n);
|
||||
} catch (EndOfFile &) { break; }
|
||||
}
|
||||
} catch (Error & e) {
|
||||
e.addTrace({}, "writing file '%1%'", path);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
string readLine(int fd)
|
||||
|
|
Loading…
Reference in a new issue