]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use -b setting when interpolating archives.
authorTim Kientzle <kientzle@gmail.com>
Sat, 26 Jun 2010 17:18:30 +0000 (13:18 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 26 Jun 2010 17:18:30 +0000 (13:18 -0400)
Simplify the handling of -b values by setting
a default early and then just using the value
instead of duplicating the logic.

SVN-Revision: 2503

tar/bsdtar.c
tar/bsdtar.h
tar/read.c
tar/write.c

index eba43bcb2b485d0fdda7b9774d8c89b0363ad285..81e422b09512754b528eb5ed68a23a856e46f1a3 100644 (file)
@@ -206,6 +206,11 @@ main(int argc, char **argv)
        if (bsdtar->filename == NULL)
                bsdtar->filename = _PATH_DEFTAPE;
 
+       /* Default block size settings. */
+       bsdtar->bytes_per_block = DEFAULT_BYTES_PER_BLOCK;
+       /* Allow library to default this unless user specifies -b. */
+       bsdtar->bytes_in_last_block = -1;
+
        /* Default: preserve mod time on extract */
        bsdtar->extract_flags = ARCHIVE_EXTRACT_TIME;
 
@@ -257,6 +262,8 @@ main(int argc, char **argv)
                                lafe_errc(1, 0,
                                    "Argument to -b is out of range (1..8192)");
                        bsdtar->bytes_per_block = 512 * t;
+                       /* Explicit -b forces last block size. */
+                       bsdtar->bytes_in_last_block = bsdtar->bytes_per_block;
                        break;
                case 'C': /* GNU tar */
                        set_chdir(bsdtar, bsdtar->optarg);
index b40bc41951a259b0c160eb6165c9af5aa5c1aca7..35bacd70a6d4b69924bd910cf18d8f15deb8017f 100644 (file)
@@ -51,6 +51,7 @@ struct bsdtar {
        time_t            newer_mtime_sec; /* --newer-mtime */
        long              newer_mtime_nsec; /* --newer-mtime-than */
        int               bytes_per_block; /* -b block_size */
+       int               bytes_in_last_block; /* See -b handling. */
        int               verbose;   /* -v */
        int               extract_flags; /* Flags for extract operation */
        int               strip_components; /* Remove this many leading dirs */
index be914233cba35c51fe8981e23b178b321eb55286..20c0b56e7acce9385f47e681c3929f5974a1998f 100644 (file)
@@ -161,9 +161,7 @@ read_archive(struct bsdtar *bsdtar, char mode)
        archive_read_support_format_all(a);
        if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options))
                lafe_errc(1, 0, "%s", archive_error_string(a));
-       if (archive_read_open_file(a, bsdtar->filename,
-           bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
-           DEFAULT_BYTES_PER_BLOCK))
+       if (archive_read_open_file(a, bsdtar->filename, bsdtar->bytes_per_block))
                lafe_errc(1, 0, "Error opening archive: %s",
                    archive_error_string(a));
 
index 6199bdd3e25e5355348b350797c30f369e4f99ed..aedb0c1646b2f25ce612b7510133eac190b9e52b 100644 (file)
@@ -198,18 +198,8 @@ tar_mode_c(struct bsdtar *bsdtar)
                usage();
        }
 
-       /*
-        * If user explicitly set the block size, then assume they
-        * want the last block padded as well.  Otherwise, use the
-        * default block size and accept archive_write_open_file()'s
-        * default padding decisions.
-        */
-       if (bsdtar->bytes_per_block != 0) {
-               archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
-               archive_write_set_bytes_in_last_block(a,
-                   bsdtar->bytes_per_block);
-       } else
-               archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
+       archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
+       archive_write_set_bytes_in_last_block(a, bsdtar->bytes_in_last_block);
 
        if (bsdtar->compress_program) {
                archive_write_set_compression_program(a, bsdtar->compress_program);
@@ -379,9 +369,8 @@ tar_mode_u(struct bsdtar *bsdtar)
        archive_read_support_compression_all(a);
        archive_read_support_format_tar(a);
        archive_read_support_format_gnutar(a);
-       if (archive_read_open_fd(a, bsdtar->fd,
-           bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
-               DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
+       if (archive_read_open_fd(a, bsdtar->fd, bsdtar->bytes_per_block)
+           != ARCHIVE_OK) {
                lafe_errc(1, 0,
                    "Can't open %s: %s", bsdtar->filename,
                    archive_error_string(a));
@@ -415,12 +404,9 @@ tar_mode_u(struct bsdtar *bsdtar)
        if (format == ARCHIVE_FORMAT_TAR_GNUTAR)
                format = ARCHIVE_FORMAT_TAR_USTAR;
        archive_write_set_format(a, format);
-       if (bsdtar->bytes_per_block != 0) {
-               archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
-               archive_write_set_bytes_in_last_block(a,
-                   bsdtar->bytes_per_block);
-       } else
-               archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
+       archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block);
+       archive_write_set_bytes_in_last_block(a, bsdtar->bytes_in_last_block);
+
        if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0)
                lafe_errc(1, errno, "Could not seek to archive end");
        if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
@@ -580,7 +566,7 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
        ina = archive_read_new();
        archive_read_support_format_all(ina);
        archive_read_support_compression_all(ina);
-       if (archive_read_open_file(ina, filename, 10240)) {
+       if (archive_read_open_file(ina, filename, bsdtar->bytes_per_block)) {
                lafe_warnc(0, "%s", archive_error_string(ina));
                bsdtar->return_value = 1;
                return (0);