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
This commit is contained in:
parent
eacc7cde7d
commit
d82088b28f
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user