* Better error checking.

This commit is contained in:
Eelco Dolstra 2006-08-31 11:40:39 +00:00
parent f93f7b75be
commit 354d58b3d7

View file

@ -79,19 +79,15 @@ static void dumpContents(const Path & path, unsigned int size,
if (fd == -1) throw SysError(format("opening file `%1%'") % path); if (fd == -1) throw SysError(format("opening file `%1%'") % path);
unsigned char buf[65536]; unsigned char buf[65536];
unsigned int left = size;
unsigned int total = 0; while (left >= 0) {
ssize_t n; size_t n = left > sizeof(buf) ? sizeof(buf) : left;
while ((n = read(fd, buf, sizeof(buf)))) { readFull(fd, buf, n);
checkInterrupt(); left -= n;
if (n == -1) throw SysError("reading file " + path);
total += n;
sink(buf, n); sink(buf, n);
} }
if (total != size)
throw SysError("file changed while reading it: " + path);
writePadding(size, sink); writePadding(size, sink);
} }
@ -231,8 +227,7 @@ static void restoreContents(int fd, const Path & path, RestoreSource & source)
unsigned int n = sizeof(buf); unsigned int n = sizeof(buf);
if (n > left) n = left; if (n > left) n = left;
source(buf, n); source(buf, n);
if (write(fd, buf, n) != (ssize_t) n) writeFull(fd, buf, n);
throw SysError("writing file " + path);
left -= n; left -= n;
} }