summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcperciva <cperciva@FreeBSD.org>2007-01-02 12:24:14 +0000
committercperciva <cperciva@FreeBSD.org>2007-01-02 12:24:14 +0000
commit1ff610fa5669c6187c0800e92e24c7139a8b416f (patch)
tree79410a60a1719ef74eb586eb1da2474e44ecd0da /usr.bin
parentd7f57382df29ac42bb9b671d05a5741c3c1c2b19 (diff)
downloadFreeBSD-src-1ff610fa5669c6187c0800e92e24c7139a8b416f.zip
FreeBSD-src-1ff610fa5669c6187c0800e92e24c7139a8b416f.tar.gz
Handle errors which occur during archive_write_data and archive_write_close
by printing an error message and exiting with a non-zero status code. MFC after: 1 week
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tar/write.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index 26e59f3..22290c9 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -404,7 +404,10 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
}
create_cleanup(bsdtar);
- archive_write_close(a);
+ if (archive_write_close(a)) {
+ bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ bsdtar->return_value = 1;
+ }
}
/*
@@ -789,7 +792,8 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, const struct stat *st,
* that case, just skip the write.
*/
if (fd >= 0 && archive_entry_size(entry) > 0)
- write_file_data(bsdtar, a, fd);
+ if (write_file_data(bsdtar, a, fd))
+ exit(1);
cleanup:
if (bsdtar->verbose)
@@ -814,13 +818,15 @@ write_file_data(struct bsdtar *bsdtar, struct archive *a, int fd)
/* XXX TODO: Allocate buffer on heap and store pointer to
* it in bsdtar structure; arrange cleanup as well. XXX */
- (void)bsdtar;
bytes_read = read(fd, buff, sizeof(buff));
while (bytes_read > 0) {
bytes_written = archive_write_data(a, buff, bytes_read);
- if (bytes_written <= 0)
- return (-1); /* Write failed; this is bad */
+ if (bytes_written <= 0) {
+ /* Write failed; this is bad */
+ bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
+ return (-1);
+ }
bytes_read = read(fd, buff, sizeof(buff));
}
return 0;
OpenPOWER on IntegriCloud