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.
This commit is contained in:
parent
e2615c73e3
commit
b63e589760
@ -155,9 +155,6 @@ tar_mode_c(struct bsdtar *bsdtar)
|
|||||||
if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL)
|
if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL)
|
||||||
bsdtar_errc(bsdtar, 1, 0, "no files or directories specified");
|
bsdtar_errc(bsdtar, 1, 0, "no files or directories specified");
|
||||||
|
|
||||||
/* We want to catch SIGINFO and SIGUSR1. */
|
|
||||||
siginfo_init(bsdtar);
|
|
||||||
|
|
||||||
a = archive_write_new();
|
a = archive_write_new();
|
||||||
|
|
||||||
/* Support any format that the library supports. */
|
/* 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));
|
bsdtar_errc(bsdtar, 1, 0, archive_error_string(a));
|
||||||
|
|
||||||
write_archive(a, 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);
|
|
||||||
|
|
||||||
/* 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. */
|
/* Sanity-test some arguments and the file. */
|
||||||
test_for_append(bsdtar);
|
test_for_append(bsdtar);
|
||||||
|
|
||||||
/* We want to catch SIGINFO and SIGUSR1. */
|
|
||||||
siginfo_init(bsdtar);
|
|
||||||
|
|
||||||
format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
|
format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED;
|
||||||
|
|
||||||
bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666);
|
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 */
|
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);
|
close(bsdtar->fd);
|
||||||
bsdtar->fd = -1;
|
bsdtar->fd = -1;
|
||||||
}
|
}
|
||||||
@ -348,9 +326,6 @@ tar_mode_u(struct bsdtar *bsdtar)
|
|||||||
/* Sanity-test some arguments and the file. */
|
/* Sanity-test some arguments and the file. */
|
||||||
test_for_append(bsdtar);
|
test_for_append(bsdtar);
|
||||||
|
|
||||||
/* We want to catch SIGINFO and SIGUSR1. */
|
|
||||||
siginfo_init(bsdtar);
|
|
||||||
|
|
||||||
bsdtar->fd = open(bsdtar->filename, O_RDWR);
|
bsdtar->fd = open(bsdtar->filename, O_RDWR);
|
||||||
if (bsdtar->fd < 0)
|
if (bsdtar->fd < 0)
|
||||||
bsdtar_errc(bsdtar, 1, errno,
|
bsdtar_errc(bsdtar, 1, errno,
|
||||||
@ -409,12 +384,6 @@ tar_mode_u(struct bsdtar *bsdtar)
|
|||||||
|
|
||||||
write_archive(a, 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);
|
close(bsdtar->fd);
|
||||||
bsdtar->fd = -1;
|
bsdtar->fd = -1;
|
||||||
|
|
||||||
@ -437,6 +406,9 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
|
|||||||
const char *arg;
|
const char *arg;
|
||||||
struct archive_entry *entry, *sparse_entry;
|
struct archive_entry *entry, *sparse_entry;
|
||||||
|
|
||||||
|
/* We want to catch SIGINFO and SIGUSR1. */
|
||||||
|
siginfo_init(bsdtar);
|
||||||
|
|
||||||
/* Allocate a buffer for file data. */
|
/* Allocate a buffer for file data. */
|
||||||
if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL)
|
if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL)
|
||||||
bsdtar_errc(bsdtar, 1, 0, "cannot allocate memory");
|
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,
|
bsdtar_warnc(bsdtar, 1, 0,
|
||||||
"Missing argument for -C");
|
"Missing argument for -C");
|
||||||
bsdtar->return_value = 1;
|
bsdtar->return_value = 1;
|
||||||
return;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_chdir(bsdtar, arg);
|
set_chdir(bsdtar, arg);
|
||||||
@ -492,8 +464,19 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
|
|||||||
bsdtar->return_value = 1;
|
bsdtar->return_value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
/* Free file data buffer. */
|
/* Free file data buffer. */
|
||||||
free(bsdtar->buff);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user