diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-08-31 11:40:39 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-08-31 11:40:39 +0000 |
commit | 354d58b3d71d8b3723ff3cb6e8311469e9548417 (patch) | |
tree | 376e9e82a96aa4f5b7913d0c3703b53c087c6ad4 /src/libutil | |
parent | f93f7b75be7851affd1288dc36d6d4c4f0d43743 (diff) |
* Better error checking.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/archive.cc | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc index 2b8fb2f10..27b1726ad 100644 --- a/src/libutil/archive.cc +++ b/src/libutil/archive.cc @@ -79,19 +79,15 @@ static void dumpContents(const Path & path, unsigned int size, if (fd == -1) throw SysError(format("opening file `%1%'") % path); unsigned char buf[65536]; + unsigned int left = size; - unsigned int total = 0; - ssize_t n; - while ((n = read(fd, buf, sizeof(buf)))) { - checkInterrupt(); - if (n == -1) throw SysError("reading file " + path); - total += n; + while (left >= 0) { + size_t n = left > sizeof(buf) ? sizeof(buf) : left; + readFull(fd, buf, n); + left -= n; sink(buf, n); } - if (total != size) - throw SysError("file changed while reading it: " + path); - writePadding(size, sink); } @@ -231,8 +227,7 @@ static void restoreContents(int fd, const Path & path, RestoreSource & source) unsigned int n = sizeof(buf); if (n > left) n = left; source(buf, n); - if (write(fd, buf, n) != (ssize_t) n) - throw SysError("writing file " + path); + writeFull(fd, buf, n); left -= n; } |