From: Tim Kientzle Date: Sat, 26 Jun 2010 17:18:30 +0000 (-0400) Subject: Use -b setting when interpolating archives. X-Git-Tag: v3.0.0a~934 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8f0b5d1d07784f40977862b040765a57dc45d7a;p=thirdparty%2Flibarchive.git Use -b setting when interpolating archives. 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 --- diff --git a/tar/bsdtar.c b/tar/bsdtar.c index eba43bcb2..81e422b09 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -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); diff --git a/tar/bsdtar.h b/tar/bsdtar.h index b40bc4195..35bacd70a 100644 --- a/tar/bsdtar.h +++ b/tar/bsdtar.h @@ -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 */ diff --git a/tar/read.c b/tar/read.c index be914233c..20c0b56e7 100644 --- a/tar/read.c +++ b/tar/read.c @@ -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)); diff --git a/tar/write.c b/tar/write.c index 6199bdd3e..aedb0c164 100644 --- a/tar/write.c +++ b/tar/write.c @@ -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);