bsdtar 2.2.3:

* Implement --use-compress-program using new libarchive feature.
  * Minor portability improvement by adjusting casts used to
    print out uids, gids, and device numbers.

Thanks to: Joerg Sonnenberger for the --use-compress-program implementation.
MFC after: 15 days
This commit is contained in:
Tim Kientzle 2007-05-29 05:39:10 +00:00
parent cebf6b9f64
commit a38d1d4c8b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=170084
6 changed files with 39 additions and 20 deletions

View File

@ -1,7 +1,7 @@
# $FreeBSD$
PROG= bsdtar
VERSION= 2.0.28
VERSION= 2.2.3
SRCS= bsdtar.c getdate.y matching.c read.c tree.c util.c write.c
WARNS?= 5
DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ}

View File

@ -360,6 +360,10 @@ Without this option,
overwrites existing files, which preserves existing hardlinks.
With this option, existing hardlinks will be broken, as will any
symlink that would affect the location of an extracted file.
.It Fl -use-compress-program Ar program
Pipe the input (in x or t mode) or the output (in c mode) through
.Pa program
instead of using the builtin compression support.
.It Fl v
Produce verbose output.
In create and extract modes,

View File

@ -145,6 +145,7 @@ enum {
OPTION_ONE_FILE_SYSTEM,
OPTION_STRIP_COMPONENTS,
OPTION_TOTALS,
OPTION_USE_COMPRESS_PROGRAM,
OPTION_VERSION
};
@ -202,6 +203,8 @@ static const struct option tar_longopts[] = {
{ "unlink", no_argument, NULL, 'U' },
{ "unlink-first", no_argument, NULL, 'U' },
{ "update", no_argument, NULL, 'u' },
{ "use-compress-program",
required_argument, NULL, OPTION_USE_COMPRESS_PROGRAM },
{ "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, OPTION_VERSION },
{ NULL, 0, NULL, 0 }
@ -558,6 +561,9 @@ main(int argc, char **argv)
usage(bsdtar);
#endif
break;
case OPTION_USE_COMPRESS_PROGRAM:
bsdtar->compress_program = optarg;
break;
default:
usage(bsdtar);
}

View File

@ -55,6 +55,7 @@ struct bsdtar {
char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
char symlink_mode; /* H or L, per BSD conventions */
char create_compression; /* j, y, or z */
const char *compress_program;
char option_absolute_paths; /* -P */
char option_dont_traverse_mounts; /* --one-file-system */
char option_fast_read; /* --fast-read */

View File

@ -106,7 +106,10 @@ read_archive(struct bsdtar *bsdtar, char mode)
include_from_file(bsdtar, bsdtar->names_from_file);
a = archive_read_new();
archive_read_support_compression_all(a);
if (bsdtar->compress_program != NULL)
archive_read_support_compression_program(a, bsdtar->compress_program);
else
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
if (archive_read_open_file(a, bsdtar->filename,
bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block :
@ -294,7 +297,7 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
/* Use uname if it's present, else uid. */
p = archive_entry_uname(entry);
if ((p == NULL) || (*p == '\0')) {
sprintf(tmp, "%d ", st->st_uid);
sprintf(tmp, "%lu ", (unsigned long)st->st_uid);
p = tmp;
}
w = strlen(p);
@ -308,7 +311,7 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
fprintf(out, "%s", p);
w = strlen(p);
} else {
sprintf(tmp, "%d", st->st_gid);
sprintf(tmp, "%lu", (unsigned long)st->st_gid);
w = strlen(tmp);
fprintf(out, "%s", tmp);
}
@ -319,9 +322,9 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
* If gs_width is too small, grow it.
*/
if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) {
sprintf(tmp, "%d,%u",
major(st->st_rdev),
(unsigned)minor(st->st_rdev)); /* ls(1) also casts here. */
sprintf(tmp, "%lu,%lu",
(unsigned long)major(st->st_rdev),
(unsigned long)minor(st->st_rdev)); /* ls(1) also casts here. */
} else {
/*
* Note the use of platform-dependent macros to format

View File

@ -203,23 +203,28 @@ tar_mode_c(struct bsdtar *bsdtar)
} else
archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK);
switch (bsdtar->create_compression) {
case 0:
break;
if (bsdtar->compress_program) {
archive_write_set_compression_program(a, bsdtar->compress_program);
} else {
switch (bsdtar->create_compression) {
case 0:
archive_write_set_compression_none(a);
break;
#ifdef HAVE_LIBBZ2
case 'j': case 'y':
archive_write_set_compression_bzip2(a);
break;
case 'j': case 'y':
archive_write_set_compression_bzip2(a);
break;
#endif
#ifdef HAVE_LIBZ
case 'z':
archive_write_set_compression_gzip(a);
break;
case 'z':
archive_write_set_compression_gzip(a);
break;
#endif
default:
bsdtar_errc(bsdtar, 1, 0,
"Unrecognized compression option -%c",
bsdtar->create_compression);
default:
bsdtar_errc(bsdtar, 1, 0,
"Unrecognized compression option -%c",
bsdtar->create_compression);
}
}
r = archive_write_open_file(a, bsdtar->filename);