diff options
author | cperciva <cperciva@FreeBSD.org> | 2008-07-05 08:10:55 +0000 |
---|---|---|
committer | cperciva <cperciva@FreeBSD.org> | 2008-07-05 08:10:55 +0000 |
commit | b63e58976016eb06a3a877ecbcffdd07c6ca0323 (patch) | |
tree | d6fd48e2f10dd83c4cc13cc1ef630b4e55ea79b5 /usr.bin/tar | |
parent | e2615c73e35aeaa1b898221ac63c1837803cdfc4 (diff) | |
download | FreeBSD-src-b63e58976016eb06a3a877ecbcffdd07c6ca0323.zip FreeBSD-src-b63e58976016eb06a3a877ecbcffdd07c6ca0323.tar.gz |
Move duplicated code from tar_mode_[cru] into archive_write.
Fix a bug I introduced 7 minutes ago: clean up properly from archive_write
if we exit the argv-handling loop due to -C not having an argument.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r-- | usr.bin/tar/write.c | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index d604095..6d7e8bb 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -155,9 +155,6 @@ tar_mode_c(struct bsdtar *bsdtar) if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL) bsdtar_errc(bsdtar, 1, 0, "no files or directories specified"); - /* We want to catch SIGINFO and SIGUSR1. */ - siginfo_init(bsdtar); - a = archive_write_new(); /* Support any format that the library supports. */ @@ -219,16 +216,6 @@ tar_mode_c(struct bsdtar *bsdtar) bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); write_archive(a, bsdtar); - - if (bsdtar->option_totals) { - fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n", - (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a)); - } - - archive_write_finish(a); - - /* Restore old SIGINFO + SIGUSR1 handlers. */ - siginfo_done(bsdtar); } /* @@ -247,9 +234,6 @@ tar_mode_r(struct bsdtar *bsdtar) /* Sanity-test some arguments and the file. */ test_for_append(bsdtar); - /* We want to catch SIGINFO and SIGUSR1. */ - siginfo_init(bsdtar); - format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666); @@ -320,12 +304,6 @@ tar_mode_r(struct bsdtar *bsdtar) write_archive(a, bsdtar); /* XXX check return val XXX */ - if (bsdtar->option_totals) { - fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n", - (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a)); - } - - archive_write_finish(a); close(bsdtar->fd); bsdtar->fd = -1; } @@ -348,9 +326,6 @@ tar_mode_u(struct bsdtar *bsdtar) /* Sanity-test some arguments and the file. */ test_for_append(bsdtar); - /* We want to catch SIGINFO and SIGUSR1. */ - siginfo_init(bsdtar); - bsdtar->fd = open(bsdtar->filename, O_RDWR); if (bsdtar->fd < 0) bsdtar_errc(bsdtar, 1, errno, @@ -409,12 +384,6 @@ tar_mode_u(struct bsdtar *bsdtar) write_archive(a, bsdtar); - if (bsdtar->option_totals) { - fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n", - (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a)); - } - - archive_write_finish(a); close(bsdtar->fd); bsdtar->fd = -1; @@ -437,6 +406,9 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) const char *arg; struct archive_entry *entry, *sparse_entry; + /* We want to catch SIGINFO and SIGUSR1. */ + siginfo_init(bsdtar); + /* Allocate a buffer for file data. */ if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL) bsdtar_errc(bsdtar, 1, 0, "cannot allocate memory"); @@ -460,7 +432,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) bsdtar_warnc(bsdtar, 1, 0, "Missing argument for -C"); bsdtar->return_value = 1; - return; + goto cleanup; } } set_chdir(bsdtar, arg); @@ -492,8 +464,19 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) bsdtar->return_value = 1; } +cleanup: /* Free file data buffer. */ free(bsdtar->buff); + + if (bsdtar->option_totals) { + fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n", + (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a)); + } + + archive_write_finish(a); + + /* Restore old SIGINFO + SIGUSR1 handlers. */ + siginfo_done(bsdtar); } /* |