mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-21 15:45:02 +00:00
If -b is specified, then force full padding for the last block.
This commit is contained in:
parent
2225b76daf
commit
e1f5ccf6fb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130169
@ -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;
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include <archive.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEFAULT_BYTES_PER_BLOCK (20*512)
|
||||
|
||||
/*
|
||||
* The internal state for the "bsdtar" program.
|
||||
*
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user