diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-06-07 03:19:57 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-06-07 03:19:57 +0000 |
commit | eadec7015b4ae23b7bb664ee0ab2e934c4376d69 (patch) | |
tree | a518bf9d34ab83fbfc5f1fda76a252a4f33ef647 /usr.bin/tar | |
parent | 299fedaaae1eb84255e6dae3fd6ea6191005e830 (diff) | |
download | FreeBSD-src-eadec7015b4ae23b7bb664ee0ab2e934c4376d69.zip FreeBSD-src-eadec7015b4ae23b7bb664ee0ab2e934c4376d69.tar.gz |
If -b is specified, then force full padding for the last block.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r-- | usr.bin/tar/bsdtar.c | 2 | ||||
-rw-r--r-- | usr.bin/tar/bsdtar.h | 2 | ||||
-rw-r--r-- | usr.bin/tar/read.c | 4 | ||||
-rw-r--r-- | usr.bin/tar/write.c | 28 |
4 files changed, 30 insertions, 6 deletions
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index 73f0854..ccf7c28 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -151,8 +151,6 @@ main(int argc, char **argv) if (bsdtar->filename == NULL) bsdtar->filename = _PATH_DEFTAPE; - bsdtar->bytes_per_block = 10240; - /* Default: preserve mod time on extract */ bsdtar->extract_flags = ARCHIVE_EXTRACT_TIME; diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h index cd63c1d..7cc7c5c 100644 --- a/usr.bin/tar/bsdtar.h +++ b/usr.bin/tar/bsdtar.h @@ -32,6 +32,8 @@ #include <archive.h> #include <stdio.h> +#define DEFAULT_BYTES_PER_BLOCK (20*512) + /* * The internal state for the "bsdtar" program. * diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c index e3850da..db34fd5 100644 --- a/usr.bin/tar/read.c +++ b/usr.bin/tar/read.c @@ -80,7 +80,9 @@ read_archive(struct bsdtar *bsdtar, char mode) a = archive_read_new(); archive_read_support_compression_all(a); archive_read_support_format_all(a); - if (archive_read_open_file(a, bsdtar->filename, bsdtar->bytes_per_block)) + if (archive_read_open_file(a, bsdtar->filename, + bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : + DEFAULT_BYTES_PER_BLOCK)) bsdtar_errc(bsdtar, 1, 0, "Error opening archive: %s", archive_error_string(a)); diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index b6c4282..12ff145 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -151,7 +151,18 @@ tar_mode_c(struct bsdtar *bsdtar) } } - archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block); + /* + * 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); switch (bsdtar->create_compression) { case 'j': case 'y': @@ -160,6 +171,10 @@ tar_mode_c(struct bsdtar *bsdtar) case 'z': archive_write_set_compression_gzip(a); break; + default: + bsdtar_errc(bsdtar, 1, 0, + "Unrecognized compression option -%c", + bsdtar->create_compression); } r = archive_write_open_file(a, bsdtar->filename); @@ -262,7 +277,9 @@ tar_mode_u(struct bsdtar *bsdtar) archive_read_support_compression_all(a); archive_read_support_format_tar(a); archive_read_support_format_gnutar(a); - archive_read_open_fd(a, bsdtar->fd, bsdtar->bytes_per_block); + archive_read_open_fd(a, bsdtar->fd, + bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : + DEFAULT_BYTES_PER_BLOCK); /* Build a list of all entries and their recorded mod times. */ while (0 == archive_read_next_header(a, &entry)) { @@ -293,7 +310,12 @@ tar_mode_u(struct bsdtar *bsdtar) if (format == ARCHIVE_FORMAT_TAR_GNUTAR) format = ARCHIVE_FORMAT_TAR_USTAR; archive_write_set_format(a, format); - archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block); + 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); lseek(bsdtar->fd, end_offset, SEEK_SET); ftruncate(bsdtar->fd, end_offset); archive_write_open_fd(a, bsdtar->fd); |