summaryrefslogtreecommitdiffstats
path: root/contrib/libarchive/tar
diff options
context:
space:
mode:
authormm <mm@FreeBSD.org>2013-03-22 13:36:03 +0000
committermm <mm@FreeBSD.org>2013-03-22 13:36:03 +0000
commit5ee0a7b76c4addc27bb45864cb4e0ce790a4b80e (patch)
treee741e3532b574e7c25aa9bb07c18cdb16139824f /contrib/libarchive/tar
parentaf89cb16bfde2fc8e93708b89daff55026d3b216 (diff)
parent366f42737cba40ceb2e83af8d17c61c0242703c5 (diff)
downloadFreeBSD-src-5ee0a7b76c4addc27bb45864cb4e0ce790a4b80e.zip
FreeBSD-src-5ee0a7b76c4addc27bb45864cb4e0ce790a4b80e.tar.gz
MFV r248590,248594:
Update libarchive to 3.1.2 Some of new features: - support for lrzip and grzip compression - support for writing tar v7 format - b64encode and uuencode filters - support for __MACOSX directory in Zip archives - support for lzop compresion (external utility)
Diffstat (limited to 'contrib/libarchive/tar')
-rw-r--r--contrib/libarchive/tar/bsdtar.191
-rw-r--r--contrib/libarchive/tar/bsdtar.c187
-rw-r--r--contrib/libarchive/tar/bsdtar.h36
-rw-r--r--contrib/libarchive/tar/cmdline.c16
-rw-r--r--contrib/libarchive/tar/creation_set.c314
-rw-r--r--contrib/libarchive/tar/read.c36
-rw-r--r--contrib/libarchive/tar/subst.c8
-rw-r--r--contrib/libarchive/tar/test/main.c246
-rw-r--r--contrib/libarchive/tar/test/test.h22
-rw-r--r--contrib/libarchive/tar/test/test_copy.c7
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.Z.uu9
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.bz2.uu7
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.grz.uu7
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.gz.uu7
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.lrz.uu9
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.lz.uu7
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.lzma.uu7
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.lzo.uu9
-rw-r--r--contrib/libarchive/tar/test/test_extract.tar.xz.uu8
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_Z.c42
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_bz2.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_grz.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_gz.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_lrz.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_lz.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_lzma.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_lzo.c48
-rw-r--r--contrib/libarchive/tar/test/test_extract_tar_xz.c48
-rw-r--r--contrib/libarchive/tar/test/test_option_a.c110
-rw-r--r--contrib/libarchive/tar/test/test_option_b64encode.c54
-rw-r--r--contrib/libarchive/tar/test/test_option_grzip.c52
-rw-r--r--contrib/libarchive/tar/test/test_option_j.c56
-rw-r--r--contrib/libarchive/tar/test/test_option_lrzip.c52
-rw-r--r--contrib/libarchive/tar/test/test_option_lzma.c57
-rw-r--r--contrib/libarchive/tar/test/test_option_lzop.c55
-rw-r--r--contrib/libarchive/tar/test/test_option_newer_than.c7
-rw-r--r--contrib/libarchive/tar/test/test_option_older_than.c85
-rw-r--r--contrib/libarchive/tar/test/test_option_r.c7
-rw-r--r--contrib/libarchive/tar/test/test_option_uuencode.c54
-rw-r--r--contrib/libarchive/tar/test/test_option_xz.c57
-rw-r--r--contrib/libarchive/tar/test/test_option_z.c55
-rw-r--r--contrib/libarchive/tar/test/test_stdio.c2
-rw-r--r--contrib/libarchive/tar/util.c24
-rw-r--r--contrib/libarchive/tar/write.c151
44 files changed, 2116 insertions, 221 deletions
diff --git a/contrib/libarchive/tar/bsdtar.1 b/contrib/libarchive/tar/bsdtar.1
index 8298544..7bb6a60 100644
--- a/contrib/libarchive/tar/bsdtar.1
+++ b/contrib/libarchive/tar/bsdtar.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 24, 2011
+.Dd November 1, 2012
.Dt TAR 1
.Os
.Sh NAME
@@ -144,6 +144,26 @@ pax-format archive on stdout.
In this way,
.Nm
can be used to convert archives from one format to another.
+.It Fl a , Fl Fl auto-compress
+(c mode only)
+Use the archive suffix to decide a set of the format and
+the compressions.
+As a simple example,
+.Dl Nm Fl a Fl cf Pa archive.tgz source.c source.h
+creates a new archive with restricted pax format and gzip compression,
+.Dl Nm Fl a Fl cf Pa archive.tar.bz2.uu source.c source.h
+creates a new archive with restricted pax format and bzip2 compression
+and uuencode compression,
+.Dl Nm Fl a Fl cf Pa archive.zip source.c source.h
+creates a new archive with zip format,
+.Dl Nm Fl a Fl jcf Pa archive.tgz source.c source.h
+ignores the
+.Dq -j
+option, and creates a new archive with restricted pax format
+and gzip compression,
+.Dl Nm Fl a Fl jcf Pa archive.xxx source.c source.h
+if it is unknown suffix or no suffix, creates a new archive with
+restricted pax format and bzip2 compression.
.It Fl B , Fl Fl read-full-blocks
Ignored for compatibility with other
.Xr tar 1
@@ -233,6 +253,9 @@ Synonym for
.Fl T .
.It Fl Fl help
Show usage.
+.It Fl Fl hfsCompression
+(x mode only)
+Mac OS X specific(v10.6 or later). Compress extracted regular files with HFS+ compression.
.It Fl Fl include Ar pattern
Process only files or directories that match the specified pattern.
Note that exclusions specified with
@@ -286,6 +309,11 @@ With this option, the target of the link will be archived instead.
.It Fl l , Fl Fl check-links
(c and r modes only)
Issue a warning message unless all links to each file are archived.
+.It Fl Fl lrzip
+(c mode only)
+Compress the resulting archive with
+.Xr lrzip 1 .
+In extract or list modes, this option is ignored.
.It Fl Fl lzma
(c mode only) Compress the resulting archive with the original LZMA algorithm.
Use of this option is discouraged and new archives should be created with
@@ -295,6 +323,11 @@ Note that, unlike other
.Nm tar
implementations, this implementation recognizes LZMA compression
automatically when reading archives.
+.It Fl Fl lzop
+(c mode only)
+Compress the resulting archive with
+.Xr lzop 1 .
+In extract or list modes, this option is ignored.
.It Fl m , Fl Fl modification-time
(x mode only)
Do not extract modification time.
@@ -323,6 +356,11 @@ except it compares mtime entries instead of ctime entries.
.It Fl Fl nodump
(c and r modes only)
Honor the nodump file flag by skipping this file.
+.It Fl Fl nopreserveHFSCompression
+(x mode only)
+Mac OS X specific(v10.6 or later). Do not compress extracted regular files
+which were compressed with HFS+ compression before archived.
+By default, compress the regular files again with HFS+ compression.
.It Fl Fl null
(use with
.Fl I
@@ -381,6 +419,24 @@ the archive will be discarded.
(c, r, u mode)
A synonym for
.Fl Fl format Ar ustar
+.It Fl Fl older Ar date
+(c, r, u modes only)
+Only include files and directories older than the specified date.
+This compares ctime entries.
+.It Fl Fl older-mtime Ar date
+(c, r, u modes only)
+Like
+.Fl Fl older ,
+except it compares mtime entries instead of ctime entries.
+.It Fl Fl older-than Pa file
+(c, r, u modes only)
+Only include files and directories older than the specified file.
+This compares ctime entries.
+.It Fl Fl older-mtime-than Pa file
+(c, r, u modes only)
+Like
+.Fl Fl older-than ,
+except it compares mtime entries instead of ctime entries.
.It Fl Fl one-file-system
(c, r, and u modes)
Do not cross mount points.
@@ -423,7 +479,23 @@ or
.Cm iso9660:!rockridge
to disable.
.It Cm gzip:compression-level
-A decimal integer from 0 to 9 specifying the gzip compression level.
+A decimal integer from 1 to 9 specifying the gzip compression level.
+.It Cm gzip:timestamp
+Store timestamp. This is enabled by default, use
+.Cm !timestamp
+or
+.Cm gzip:!timestamp
+to disable.
+.It Cm lrzip:compression Ns = Ns Ar type
+Use
+.Ar type
+as compression method.
+Supported values are bzip2, gzip, lzo (ultra fast),
+and zpaq (best, extremely slow).
+.It Cm lrzip:compression-level
+A decimal integer from 1 to 9 specifying the lrzip compression level.
+.It Cm lzop:compression-level
+A decimal integer from 1 to 9 specifying the lzop compression level.
.It Cm xz:compression-level
A decimal integer from 0 to 9 specifying the xz compression level.
.It Cm mtree: Ns Ar keyword
@@ -565,6 +637,11 @@ Note that
.Fl Fl null
also disables the special handling of lines containing
.Dq -C .
+Note: If you are generating lists of files using
+.Xr find 1 ,
+you probably want to use
+.Fl n
+as well.
.It Fl Fl totals
(c, r, u mode only)
After archiving all files, print a summary to stderr.
@@ -660,6 +737,16 @@ automatically when reading archives.
The following environment variables affect the execution of
.Nm :
.Bl -tag -width ".Ev BLOCKSIZE"
+.It Ev TAR_READER_OPTIONS
+The default options for format readers and compression readers.
+The
+.Fl Fl options
+option overrides this.
+.It Ev TAR_WRITER_OPTIONS
+The default options for format writers and compression writers.
+The
+.Fl Fl options
+option overrides this.
.It Ev LANG
The locale to use.
See
diff --git a/contrib/libarchive/tar/bsdtar.c b/contrib/libarchive/tar/bsdtar.c
index 50f9c99..194d798 100644
--- a/contrib/libarchive/tar/bsdtar.c
+++ b/contrib/libarchive/tar/bsdtar.c
@@ -134,7 +134,10 @@ main(int argc, char **argv)
{
struct bsdtar *bsdtar, bsdtar_storage;
int opt, t;
- char option_o;
+ char compression, compression2;
+ const char *compression_name, *compression2_name;
+ const char *compress_program;
+ char option_a, option_o;
char possible_help_request;
char buff[16];
@@ -147,7 +150,10 @@ main(int argc, char **argv)
bsdtar->fd = -1; /* Mark as "unused" */
bsdtar->gid = -1;
bsdtar->uid = -1;
- option_o = 0;
+ option_a = option_o = 0;
+ compression = compression2 = '\0';
+ compression_name = compression2_name = NULL;
+ compress_program = NULL;
#if defined(HAVE_SIGACTION)
{ /* Set up signal handling. */
@@ -243,6 +249,9 @@ main(int argc, char **argv)
bsdtar->matching = archive_match_new();
if (bsdtar->matching == NULL)
lafe_errc(1, errno, "Out of memory");
+ bsdtar->cset = cset_new();
+ if (bsdtar->cset == NULL)
+ lafe_errc(1, errno, "Out of memory");
bsdtar->argv = argv;
bsdtar->argc = argc;
@@ -255,6 +264,9 @@ main(int argc, char **argv)
*/
while ((opt = bsdtar_getopt(bsdtar)) != -1) {
switch (opt) {
+ case 'a': /* GNU tar */
+ option_a = 1; /* Record it and resolve it later. */
+ break;
case 'B': /* GNU tar */
/* libarchive doesn't need this; just ignore it. */
break;
@@ -267,6 +279,14 @@ main(int argc, char **argv)
/* Explicit -b forces last block size. */
bsdtar->bytes_in_last_block = bsdtar->bytes_per_block;
break;
+ case OPTION_B64ENCODE:
+ if (compression2 != '\0')
+ lafe_errc(1, 0,
+ "Can't specify both --uuencode and "
+ "--b64encode");
+ compression2 = opt;
+ compression2_name = "b64encode";
+ break;
case 'C': /* GNU tar */
if (strlen(bsdtar->argument) == 0)
lafe_errc(1, 0,
@@ -293,7 +313,7 @@ main(int argc, char **argv)
"Couldn't exclude %s\n", bsdtar->argument);
break;
case OPTION_FORMAT: /* GNU tar, others */
- bsdtar->create_format = bsdtar->argument;
+ cset_set_format(bsdtar->cset, bsdtar->argument);
break;
case 'f': /* SUSv2 */
bsdtar->filename = bsdtar->argument;
@@ -308,6 +328,14 @@ main(int argc, char **argv)
case OPTION_GNAME: /* cpio */
bsdtar->gname = bsdtar->argument;
break;
+ case OPTION_GRZIP:
+ if (compression != '\0')
+ lafe_errc(1, 0,
+ "Can't specify both -%c and -%c", opt,
+ compression);
+ compression = opt;
+ compression_name = "grzip";
+ break;
case 'H': /* BSD convention */
bsdtar->symlink_mode = 'H';
break;
@@ -320,6 +348,10 @@ main(int argc, char **argv)
long_help();
exit(0);
break;
+ case OPTION_HFS_COMPRESSION: /* Mac OS X v10.6 or later */
+ bsdtar->extract_flags |=
+ ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED;
+ break;
case 'I': /* GNU tar */
/*
* TODO: Allow 'names' to come from an archive,
@@ -346,18 +378,20 @@ main(int argc, char **argv)
bsdtar->argument);
break;
case 'j': /* GNU tar */
- if (bsdtar->create_compression != '\0')
+ if (compression != '\0')
lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
- bsdtar->create_compression);
- bsdtar->create_compression = opt;
+ compression);
+ compression = opt;
+ compression_name = "bzip2";
break;
case 'J': /* GNU tar 1.21 and later */
- if (bsdtar->create_compression != '\0')
+ if (compression != '\0')
lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
- bsdtar->create_compression);
- bsdtar->create_compression = opt;
+ compression);
+ compression = opt;
+ compression_name = "xz";
break;
case 'k': /* GNU tar */
bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
@@ -372,13 +406,21 @@ main(int argc, char **argv)
/* GNU tar 1.13 used -l for --one-file-system */
bsdtar->option_warn_links = 1;
break;
+ case OPTION_LRZIP:
case OPTION_LZIP: /* GNU tar beginning with 1.23 */
case OPTION_LZMA: /* GNU tar beginning with 1.20 */
- if (bsdtar->create_compression != '\0')
+ case OPTION_LZOP: /* GNU tar beginning with 1.21 */
+ if (compression != '\0')
lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
- bsdtar->create_compression);
- bsdtar->create_compression = opt;
+ compression);
+ compression = opt;
+ switch (opt) {
+ case OPTION_LRZIP: compression_name = "lrzip"; break;
+ case OPTION_LZIP: compression_name = "lzip"; break;
+ case OPTION_LZMA: compression_name = "lzma"; break;
+ case OPTION_LZOP: compression_name = "lzop"; break;
+ }
break;
case 'm': /* SUSv2 */
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME;
@@ -391,7 +433,6 @@ main(int argc, char **argv)
* --newer-?time='date' Only files newer than 'date'
* --newer-?time-than='file' Only files newer than time
* on specified file (useful for incremental backups)
- * TODO: Add corresponding "older" options to reverse these.
*/
case OPTION_NEWER_CTIME: /* GNU tar */
if (archive_match_include_date(bsdtar->matching,
@@ -424,6 +465,11 @@ main(int argc, char **argv)
case OPTION_NODUMP: /* star */
bsdtar->readdisk_flags |= ARCHIVE_READDISK_HONOR_NODUMP;
break;
+ case OPTION_NOPRESERVE_HFS_COMPRESSION:
+ /* Mac OS X v10.6 or later */
+ bsdtar->extract_flags |=
+ ARCHIVE_EXTRACT_NO_HFS_COMPRESSION;
+ break;
case OPTION_NO_SAME_OWNER: /* GNU tar */
bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
break;
@@ -448,6 +494,40 @@ main(int argc, char **argv)
case 'o': /* SUSv2 and GNU conflict here, but not fatally */
option_o = 1; /* Record it and resolve it later. */
break;
+ /*
+ * Selecting files by time:
+ * --older-?time='date' Only files older than 'date'
+ * --older-?time-than='file' Only files older than time
+ * on specified file
+ */
+ case OPTION_OLDER_CTIME:
+ if (archive_match_include_date(bsdtar->matching,
+ ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER,
+ bsdtar->argument) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(bsdtar->matching));
+ break;
+ case OPTION_OLDER_CTIME_THAN:
+ if (archive_match_include_file_time(bsdtar->matching,
+ ARCHIVE_MATCH_CTIME | ARCHIVE_MATCH_OLDER,
+ bsdtar->argument) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(bsdtar->matching));
+ break;
+ case OPTION_OLDER_MTIME:
+ if (archive_match_include_date(bsdtar->matching,
+ ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER,
+ bsdtar->argument) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(bsdtar->matching));
+ break;
+ case OPTION_OLDER_MTIME_THAN:
+ if (archive_match_include_file_time(bsdtar->matching,
+ ARCHIVE_MATCH_MTIME | ARCHIVE_MATCH_OLDER,
+ bsdtar->argument) != ARCHIVE_OK)
+ lafe_errc(1, 0, "Error : %s",
+ archive_error_string(bsdtar->matching));
+ break;
case OPTION_ONE_FILE_SYSTEM: /* GNU tar */
bsdtar->readdisk_flags |=
ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS;
@@ -478,7 +558,7 @@ main(int argc, char **argv)
bsdtar->extract_flags |= ARCHIVE_EXTRACT_MAC_METADATA;
break;
case OPTION_POSIX: /* GNU tar */
- bsdtar->create_format = "pax";
+ cset_set_format(bsdtar->cset, "pax");
break;
case 'q': /* FreeBSD GNU tar --fast-read, NetBSD -q */
bsdtar->option_fast_read = 1;
@@ -490,7 +570,7 @@ main(int argc, char **argv)
bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE;
break;
case 's': /* NetBSD pax-as-tar */
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
add_substitution(bsdtar, bsdtar->argument);
#else
lafe_warnc(0,
@@ -537,6 +617,14 @@ main(int argc, char **argv)
case OPTION_UNAME: /* cpio */
bsdtar->uname = bsdtar->argument;
break;
+ case OPTION_UUENCODE:
+ if (compression2 != '\0')
+ lafe_errc(1, 0,
+ "Can't specify both --uuencode and "
+ "--b64encode");
+ compression2 = opt;
+ compression2_name = "uuencode";
+ break;
case 'v': /* SUSv2 */
bsdtar->verbose++;
break;
@@ -565,28 +653,31 @@ main(int argc, char **argv)
set_mode(bsdtar, opt);
break;
case 'y': /* FreeBSD version of GNU tar */
- if (bsdtar->create_compression != '\0')
+ if (compression != '\0')
lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
- bsdtar->create_compression);
- bsdtar->create_compression = opt;
+ compression);
+ compression = opt;
+ compression_name = "bzip2";
break;
case 'Z': /* GNU tar */
- if (bsdtar->create_compression != '\0')
+ if (compression != '\0')
lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
- bsdtar->create_compression);
- bsdtar->create_compression = opt;
+ compression);
+ compression = opt;
+ compression_name = "compress";
break;
case 'z': /* GNU tar, star, many others */
- if (bsdtar->create_compression != '\0')
+ if (compression != '\0')
lafe_errc(1, 0,
"Can't specify both -%c and -%c", opt,
- bsdtar->create_compression);
- bsdtar->create_compression = opt;
+ compression);
+ compression = opt;
+ compression_name = "gzip";
break;
case OPTION_USE_COMPRESS_PROGRAM:
- bsdtar->compress_program = bsdtar->argument;
+ compress_program = bsdtar->argument;
break;
default:
usage();
@@ -609,10 +700,16 @@ main(int argc, char **argv)
"Must specify one of -c, -r, -t, -u, -x");
/* Check boolean options only permitted in certain modes. */
+ if (option_a)
+ only_mode(bsdtar, "-a", "c");
if (bsdtar->readdisk_flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS)
only_mode(bsdtar, "--one-file-system", "cru");
if (bsdtar->option_fast_read)
only_mode(bsdtar, "--fast-read", "xt");
+ if (bsdtar->extract_flags & ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED)
+ only_mode(bsdtar, "--hfsCompression", "x");
+ if (bsdtar->extract_flags & ARCHIVE_EXTRACT_NO_HFS_COMPRESSION)
+ only_mode(bsdtar, "--nopreserveHFSCompression", "x");
if (bsdtar->readdisk_flags & ARCHIVE_READDISK_HONOR_NODUMP)
only_mode(bsdtar, "--nodump", "cru");
if (option_o > 0) {
@@ -623,7 +720,7 @@ main(int argc, char **argv)
* "ustar" format is the closest thing
* supported by libarchive.
*/
- bsdtar->create_format = "ustar";
+ cset_set_format(bsdtar->cset, "ustar");
/* TODO: bsdtar->create_format = "v7"; */
break;
case 'x':
@@ -645,13 +742,40 @@ main(int argc, char **argv)
if (bsdtar->option_warn_links)
only_mode(bsdtar, "--check-links", "cr");
+ if (option_a && cset_auto_compress(bsdtar->cset, bsdtar->filename)) {
+ /* Ignore specified compressions if auto-compress works. */
+ compression = '\0';
+ compression2 = '\0';
+ }
/* Check other parameters only permitted in certain modes. */
- if (bsdtar->create_compression != '\0') {
- strcpy(buff, "-?");
- buff[1] = bsdtar->create_compression;
+ if (compress_program != NULL) {
+ only_mode(bsdtar, "--use-compress-program", "cxt");
+ cset_add_filter_program(bsdtar->cset, compress_program);
+ /* Ignore specified compressions. */
+ compression = '\0';
+ compression2 = '\0';
+ }
+ if (compression != '\0') {
+ switch (compression) {
+ case 'J': case 'j': case 'y': case 'Z': case 'z':
+ strcpy(buff, "-?");
+ buff[1] = compression;
+ break;
+ default:
+ strcpy(buff, "--");
+ strcat(buff, compression_name);
+ break;
+ }
+ only_mode(bsdtar, buff, "cxt");
+ cset_add_filter(bsdtar->cset, compression_name);
+ }
+ if (compression2 != '\0') {
+ strcpy(buff, "--");
+ strcat(buff, compression2_name);
only_mode(bsdtar, buff, "cxt");
+ cset_add_filter(bsdtar->cset, compression2_name);
}
- if (bsdtar->create_format != NULL)
+ if (cset_get_format(bsdtar->cset) != NULL)
only_mode(bsdtar, "--format", "cru");
if (bsdtar->symlink_mode != '\0') {
strcpy(buff, "-?");
@@ -682,9 +806,10 @@ main(int argc, char **argv)
}
archive_match_free(bsdtar->matching);
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
cleanup_substitution(bsdtar);
#endif
+ cset_free(bsdtar->cset);
if (bsdtar->return_value != 0)
lafe_warnc(0,
diff --git a/contrib/libarchive/tar/bsdtar.h b/contrib/libarchive/tar/bsdtar.h
index 1528c48..8c14fce 100644
--- a/contrib/libarchive/tar/bsdtar.h
+++ b/contrib/libarchive/tar/bsdtar.h
@@ -29,7 +29,11 @@
#include <stdio.h>
#define DEFAULT_BYTES_PER_BLOCK (20*512)
+#define ENV_READER_OPTIONS "TAR_READER_OPTIONS"
+#define ENV_WRITER_OPTIONS "TAR_WRITER_OPTIONS"
+#define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__,"
+struct creation_set;
/*
* The internal state for the "bsdtar" program.
*
@@ -41,7 +45,6 @@
struct bsdtar {
/* Options */
const char *filename; /* -f filename */
- const char *create_format; /* -F format */
char *pending_chdir; /* -C dir */
const char *names_from_file; /* -T file */
int bytes_per_block; /* -b block_size */
@@ -56,8 +59,6 @@ struct bsdtar {
const char *uname; /* --uname */
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_chroot; /* --chroot */
char option_fast_read; /* --fast-read */
@@ -72,6 +73,7 @@ struct bsdtar {
char option_unlink_first; /* -U */
char option_warn_links; /* --check-links */
char day_first; /* show day before month in -tv output */
+ struct creation_set *cset;
/* Option parser state */
int getopt_state;
@@ -111,27 +113,37 @@ struct bsdtar {
/* Fake short equivalents for long options that otherwise lack them. */
enum {
- OPTION_CHECK_LINKS = 1,
+ OPTION_B64ENCODE = 1,
+ OPTION_CHECK_LINKS,
OPTION_CHROOT,
OPTION_DISABLE_COPYFILE,
OPTION_EXCLUDE,
OPTION_FORMAT,
OPTION_GID,
OPTION_GNAME,
+ OPTION_GRZIP,
OPTION_HELP,
+ OPTION_HFS_COMPRESSION,
OPTION_INCLUDE,
OPTION_KEEP_NEWER_FILES,
+ OPTION_LRZIP,
OPTION_LZIP,
OPTION_LZMA,
+ OPTION_LZOP,
OPTION_NEWER_CTIME,
OPTION_NEWER_CTIME_THAN,
OPTION_NEWER_MTIME,
OPTION_NEWER_MTIME_THAN,
OPTION_NODUMP,
+ OPTION_NOPRESERVE_HFS_COMPRESSION,
OPTION_NO_SAME_OWNER,
OPTION_NO_SAME_PERMISSIONS,
OPTION_NULL,
OPTION_NUMERIC_OWNER,
+ OPTION_OLDER_CTIME,
+ OPTION_OLDER_CTIME_THAN,
+ OPTION_OLDER_MTIME,
+ OPTION_OLDER_MTIME_THAN,
OPTION_ONE_FILE_SYSTEM,
OPTION_OPTIONS,
OPTION_POSIX,
@@ -141,6 +153,7 @@ enum {
OPTION_UID,
OPTION_UNAME,
OPTION_USE_COMPRESS_PROGRAM,
+ OPTION_UUENCODE,
OPTION_VERSION
};
@@ -160,8 +173,21 @@ void tar_mode_x(struct bsdtar *bsdtar);
void usage(void);
int yes(const char *fmt, ...);
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
void add_substitution(struct bsdtar *, const char *);
int apply_substitution(struct bsdtar *, const char *, char **, int, int);
void cleanup_substitution(struct bsdtar *);
#endif
+
+void cset_add_filter(struct creation_set *, const char *);
+void cset_add_filter_program(struct creation_set *, const char *);
+int cset_auto_compress(struct creation_set *, const char *);
+void cset_free(struct creation_set *);
+const char * cset_get_format(struct creation_set *);
+struct creation_set *cset_new(void);
+int cset_read_support_filter_program(struct creation_set *,
+ struct archive *);
+void cset_set_format(struct creation_set *, const char *);
+int cset_write_add_filters(struct creation_set *,
+ struct archive *, const void **);
+
diff --git a/contrib/libarchive/tar/cmdline.c b/contrib/libarchive/tar/cmdline.c
index 83bbda1..4444b80 100644
--- a/contrib/libarchive/tar/cmdline.c
+++ b/contrib/libarchive/tar/cmdline.c
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
* Short options for tar. Please keep this sorted.
*/
static const char *short_options
- = "Bb:C:cf:HhI:JjkLlmnOoPpqrSs:T:tUuvW:wX:xyZz";
+ = "aBb:C:cf:HhI:JjkLlmnOoPpqrSs:T:tUuvW:wX:xyZz";
/*
* Long options for tar. Please keep this list sorted.
@@ -65,6 +65,8 @@ static const struct bsdtar_option {
} tar_longopts[] = {
{ "absolute-paths", 0, 'P' },
{ "append", 0, 'r' },
+ { "auto-compress", 0, 'a' },
+ { "b64encode", 0, OPTION_B64ENCODE },
{ "block-size", 1, 'b' },
{ "bunzip2", 0, 'j' },
{ "bzip", 0, 'j' },
@@ -87,17 +89,21 @@ static const struct bsdtar_option {
{ "format", 1, OPTION_FORMAT },
{ "gid", 1, OPTION_GID },
{ "gname", 1, OPTION_GNAME },
+ { "grzip", 0, OPTION_GRZIP },
{ "gunzip", 0, 'z' },
{ "gzip", 0, 'z' },
{ "help", 0, OPTION_HELP },
+ { "hfsCompression", 0, OPTION_HFS_COMPRESSION },
{ "include", 1, OPTION_INCLUDE },
{ "insecure", 0, 'P' },
{ "interactive", 0, 'w' },
{ "keep-newer-files", 0, OPTION_KEEP_NEWER_FILES },
{ "keep-old-files", 0, 'k' },
{ "list", 0, 't' },
+ { "lrzip", 0, OPTION_LRZIP },
{ "lzip", 0, OPTION_LZIP },
{ "lzma", 0, OPTION_LZMA },
+ { "lzop", 0, OPTION_LZOP },
{ "modification-time", 0, 'm' },
{ "newer", 1, OPTION_NEWER_CTIME },
{ "newer-ctime", 1, OPTION_NEWER_CTIME },
@@ -109,9 +115,16 @@ static const struct bsdtar_option {
{ "no-same-owner", 0, OPTION_NO_SAME_OWNER },
{ "no-same-permissions", 0, OPTION_NO_SAME_PERMISSIONS },
{ "nodump", 0, OPTION_NODUMP },
+ { "nopreserveHFSCompression",0, OPTION_NOPRESERVE_HFS_COMPRESSION },
{ "norecurse", 0, 'n' },
{ "null", 0, OPTION_NULL },
{ "numeric-owner", 0, OPTION_NUMERIC_OWNER },
+ { "older", 1, OPTION_OLDER_CTIME },
+ { "older-ctime", 1, OPTION_OLDER_CTIME },
+ { "older-ctime-than", 1, OPTION_OLDER_CTIME_THAN },
+ { "older-mtime", 1, OPTION_OLDER_MTIME },
+ { "older-mtime-than", 1, OPTION_OLDER_MTIME_THAN },
+ { "older-than", 1, OPTION_OLDER_CTIME_THAN },
{ "one-file-system", 0, OPTION_ONE_FILE_SYSTEM },
{ "options", 1, OPTION_OPTIONS },
{ "posix", 0, OPTION_POSIX },
@@ -129,6 +142,7 @@ static const struct bsdtar_option {
{ "unlink-first", 0, 'U' },
{ "update", 0, 'u' },
{ "use-compress-program", 1, OPTION_USE_COMPRESS_PROGRAM },
+ { "uuencode", 0, OPTION_UUENCODE },
{ "verbose", 0, 'v' },
{ "version", 0, OPTION_VERSION },
{ "xz", 0, 'J' },
diff --git a/contrib/libarchive/tar/creation_set.c b/contrib/libarchive/tar/creation_set.c
new file mode 100644
index 0000000..3d7764d
--- /dev/null
+++ b/contrib/libarchive/tar/creation_set.c
@@ -0,0 +1,314 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "bsdtar_platform.h"
+__FBSDID("$FreeBSD$");
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "bsdtar.h"
+#include "err.h"
+
+struct creation_set {
+ char *create_format;
+ struct filter_set {
+ int program; /* Set 1 if filter is a program name */
+ char *filter_name;
+ } *filters;
+ int filter_count;
+};
+
+struct suffix_code_t {
+ const char *suffix;
+ const char *form;
+};
+
+static const char *
+get_suffix_code(const struct suffix_code_t *tbl, const char *suffix)
+{
+ int i;
+
+ if (suffix == NULL)
+ return (NULL);
+ for (i = 0; tbl[i].suffix != NULL; i++) {
+ if (strcmp(tbl[i].suffix, suffix) == 0)
+ return (tbl[i].form);
+ }
+ return (NULL);
+}
+
+static const char *
+get_filter_code(const char *suffix)
+{
+ /* A pair of suffix and compression/filter. */
+ static const struct suffix_code_t filters[] = {
+ { ".Z", "compress" },
+ { ".bz2", "bzip2" },
+ { ".gz", "gzip" },
+ { ".grz", "grzip" },
+ { ".lrz", "lrzip" },
+ { ".lz", "lzip" },
+ { ".lzo", "lzop" },
+ { ".lzma", "lzma" },
+ { ".uu", "uuencode" },
+ { ".xz", "xz" },
+ { NULL, NULL }
+ };
+
+ return get_suffix_code(filters, suffix);
+}
+
+static const char *
+get_format_code(const char *suffix)
+{
+ /* A pair of suffix and format. */
+ static const struct suffix_code_t formats[] = {
+ { ".7z", "7zip" },
+ { ".ar", "arbsd" },
+ { ".cpio", "cpio" },
+ { ".iso", "iso9960" },
+ { ".mtree", "mtree" },
+ { ".shar", "shar" },
+ { ".tar", "paxr" },
+ { ".xar", "xar" },
+ { ".zip", "zip" },
+ { NULL, NULL }
+ };
+
+ return get_suffix_code(formats, suffix);
+}
+
+static const char *
+decompose_alias(const char *suffix)
+{
+ static const struct suffix_code_t alias[] = {
+ { ".taz", ".tar.gz" },
+ { ".tgz", ".tar.gz" },
+ { ".tbz", ".tar.bz2" },
+ { ".tbz2", ".tar.bz2" },
+ { ".tz2", ".tar.bz2" },
+ { ".tlz", ".tar.lzma" },
+ { ".txz", ".tar.xz" },
+ { ".tzo", ".tar.lzo" },
+ { ".taZ", ".tar.Z" },
+ { ".tZ", ".tar.Z" },
+ { NULL, NULL }
+ };
+
+ return get_suffix_code(alias, suffix);
+}
+
+static void
+_cset_add_filter(struct creation_set *cset, int program, const char *filter)
+{
+ struct filter_set *new_ptr;
+ char *new_filter;
+
+ new_ptr = (struct filter_set *)realloc(cset->filters,
+ sizeof(*cset->filters) * (cset->filter_count + 1));
+ if (new_ptr == NULL)
+ lafe_errc(1, 0, "No memory");
+ new_filter = strdup(filter);
+ if (new_filter == NULL)
+ lafe_errc(1, 0, "No memory");
+ cset->filters = new_ptr;
+ cset->filters[cset->filter_count].program = program;
+ cset->filters[cset->filter_count].filter_name = new_filter;
+ cset->filter_count++;
+}
+
+void
+cset_add_filter(struct creation_set *cset, const char *filter)
+{
+ _cset_add_filter(cset, 0, filter);
+}
+
+void
+cset_add_filter_program(struct creation_set *cset, const char *filter)
+{
+ _cset_add_filter(cset, 1, filter);
+}
+
+int
+cset_read_support_filter_program(struct creation_set *cset, struct archive *a)
+{
+ int cnt = 0, i;
+
+ for (i = 0; i < cset->filter_count; i++) {
+ if (cset->filters[i].program) {
+ archive_read_support_filter_program(a,
+ cset->filters[i].filter_name);
+ ++cnt;
+ }
+ }
+ return (cnt);
+}
+
+int
+cset_write_add_filters(struct creation_set *cset, struct archive *a,
+ const void **filter_name)
+{
+ int cnt = 0, i, r;
+
+ for (i = 0; i < cset->filter_count; i++) {
+ if (cset->filters[i].program)
+ r = archive_write_add_filter_program(a,
+ cset->filters[i].filter_name);
+ else
+ r = archive_write_add_filter_by_name(a,
+ cset->filters[i].filter_name);
+ if (r < ARCHIVE_WARN) {
+ *filter_name = cset->filters[i].filter_name;
+ return (r);
+ }
+ ++cnt;
+ }
+ return (cnt);
+}
+
+void
+cset_set_format(struct creation_set *cset, const char *format)
+{
+ char *f;
+
+ f = strdup(format);
+ if (f == NULL)
+ lafe_errc(1, 0, "No memory");
+ free(cset->create_format);
+ cset->create_format = f;
+}
+
+const char *
+cset_get_format(struct creation_set *cset)
+{
+ return (cset->create_format);
+}
+
+static void
+_cleanup_filters(struct filter_set *filters, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ free(filters[i].filter_name);
+ free(filters);
+}
+
+/*
+ * Clean up a creation set.
+ */
+void
+cset_free(struct creation_set *cset)
+{
+ _cleanup_filters(cset->filters, cset->filter_count);
+ free(cset->create_format);
+ free(cset);
+}
+
+struct creation_set *
+cset_new(void)
+{
+ return calloc(1, sizeof(struct creation_set));
+}
+
+/*
+ * Build a creation set by a file name suffix.
+ */
+int
+cset_auto_compress(struct creation_set *cset, const char *filename)
+{
+ struct filter_set *old_filters;
+ char *name, *p;
+ const char *code;
+ int old_filter_count;
+
+ name = strdup(filename);
+ if (name == NULL)
+ lafe_errc(1, 0, "No memory");
+ /* Save previous filters. */
+ old_filters = cset->filters;
+ old_filter_count = cset->filter_count;
+ cset->filters = NULL;
+ cset->filter_count = 0;
+
+ for (;;) {
+ /* Get the suffix. */
+ p = strrchr(name, '.');
+ if (p == NULL)
+ break;
+ /* Suppose it indicates compression/filter type
+ * such as ".gz". */
+ code = get_filter_code(p);
+ if (code != NULL) {
+ cset_add_filter(cset, code);
+ *p = '\0';
+ continue;
+ }
+ /* Suppose it indicates format type such as ".tar". */
+ code = get_format_code(p);
+ if (code != NULL) {
+ cset_set_format(cset, code);
+ break;
+ }
+ /* Suppose it indicates alias such as ".tgz". */
+ code = decompose_alias(p);
+ if (code == NULL)
+ break;
+ /* Replace the suffix. */
+ *p = '\0';
+ name = realloc(name, strlen(name) + strlen(code) + 1);
+ if (name == NULL)
+ lafe_errc(1, 0, "No memory");
+ strcat(name, code);
+ }
+ free(name);
+ if (cset->filters) {
+ struct filter_set *v;
+ int i, r;
+
+ /* Release previos filters. */
+ _cleanup_filters(old_filters, old_filter_count);
+
+ v = malloc(sizeof(*v) * cset->filter_count);
+ if (v == NULL)
+ lafe_errc(1, 0, "No memory");
+ /* Reverse filter sequence. */
+ for (i = 0, r = cset->filter_count; r > 0; )
+ v[i++] = cset->filters[--r];
+ free(cset->filters);
+ cset->filters = v;
+ return (1);
+ } else {
+ /* Put previos filters back. */
+ cset->filters = old_filters;
+ cset->filter_count = old_filter_count;
+ return (0);
+ }
+}
diff --git a/contrib/libarchive/tar/read.c b/contrib/libarchive/tar/read.c
index 87ee735..67a6600 100644
--- a/contrib/libarchive/tar/read.c
+++ b/contrib/libarchive/tar/read.c
@@ -125,8 +125,8 @@ progress_func(void *cookie)
if (bsdtar->verbose)
fprintf(stderr, "\n");
if (a != NULL) {
- comp = archive_position_compressed(a);
- uncomp = archive_position_uncompressed(a);
+ comp = archive_filter_bytes(a, -1);
+ uncomp = archive_filter_bytes(a, 0);
if (comp > uncomp)
compression = 0;
else
@@ -155,6 +155,7 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
FILE *out;
struct archive *a;
struct archive_entry *entry;
+ const char *reader_options;
int r;
while (*bsdtar->argv) {
@@ -173,14 +174,35 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
archive_error_string(bsdtar->matching));
a = archive_read_new();
- if (bsdtar->compress_program != NULL)
- archive_read_support_filter_program(a, bsdtar->compress_program);
- else
+ if (cset_read_support_filter_program(bsdtar->cset, a) == 0)
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
+
+ reader_options = getenv(ENV_READER_OPTIONS);
+ if (reader_options != NULL) {
+ char *p;
+ /* Set default read options. */
+ p = malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
+ + strlen(reader_options) + 1);
+ if (p == NULL)
+ lafe_errc(1, errno, "Out of memory");
+ /* Prepend magic code to ignore options for
+ * a format or modules which are not added to
+ * the archive read object. */
+ strncpy(p, IGNORE_WRONG_MODULE_NAME,
+ sizeof(IGNORE_WRONG_MODULE_NAME) -1);
+ strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, reader_options);
+ r = archive_read_set_options(a, p);
+ free(p);
+ if (r == ARCHIVE_FATAL)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ else
+ archive_clear_error(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))
+ if (archive_read_open_filename(a, bsdtar->filename,
+ bsdtar->bytes_per_block))
lafe_errc(1, 0, "Error opening archive: %s",
archive_error_string(a));
@@ -338,7 +360,7 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
if (bsdtar->verbose > 2)
fprintf(stdout, "Archive Format: %s, Compression: %s\n",
- archive_format_name(a), archive_compression_name(a));
+ archive_format_name(a), archive_filter_name(a, 0));
archive_read_free(a);
}
diff --git a/contrib/libarchive/tar/subst.c b/contrib/libarchive/tar/subst.c
index b592fe0..2e05054 100644
--- a/contrib/libarchive/tar/subst.c
+++ b/contrib/libarchive/tar/subst.c
@@ -26,11 +26,15 @@
#include "bsdtar_platform.h"
__FBSDID("$FreeBSD$");
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
#include "bsdtar.h"
#include <errno.h>
+#ifdef HAVE_PCREPOSIX_H
+#include <pcreposix.h>
+#else
#include <regex.h>
+#endif
#include <stdlib.h>
#include <string.h>
@@ -317,4 +321,4 @@ cleanup_substitution(struct bsdtar *bsdtar)
}
free(subst);
}
-#endif /* HAVE_REGEX_H */
+#endif /* defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) */
diff --git a/contrib/libarchive/tar/test/main.c b/contrib/libarchive/tar/test/main.c
index 0d617e3..bce0bd6 100644
--- a/contrib/libarchive/tar/test/main.c
+++ b/contrib/libarchive/tar/test/main.c
@@ -24,6 +24,7 @@
*/
#include "test.h"
+#include "test_utils.h"
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
@@ -91,6 +92,7 @@ __FBSDID("$FreeBSD$");
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <io.h>
+#include <direct.h>
#include <windows.h>
#ifndef F_OK
#define F_OK (0)
@@ -389,7 +391,6 @@ failure_finish(void *extra)
fprintf(stderr,
" *** forcing core dump so failure can be debugged ***\n");
abort();
- exit(1);
}
}
@@ -622,8 +623,8 @@ assertion_equal_string(const char *file, int line,
if (v1 == v2 || (v1 != NULL && v2 != NULL && strcmp(v1, v2) == 0))
return (1);
failure_start(file, line, "%s != %s", e1, e2);
- l1 = strlen(e1);
- l2 = strlen(e2);
+ l1 = (int)strlen(e1);
+ l2 = (int)strlen(e2);
if (l1 < l2)
l1 = l2;
strdump(e1, v1, l1, utf8);
@@ -746,6 +747,8 @@ assertion_equal_mem(const char *file, int line,
assertion_count(file, line);
if (v1 == v2 || (v1 != NULL && v2 != NULL && memcmp(v1, v2, l) == 0))
return (1);
+ if (v1 == NULL || v2 == NULL)
+ return (0);
failure_start(file, line, "%s != %s", e1, e2);
logprintf(" size %s = %d\n", ld, (int)l);
@@ -839,9 +842,14 @@ assertion_equal_file(const char *filename, int line, const char *fn1, const char
f1 = fopen(fn1, "rb");
f2 = fopen(fn2, "rb");
+ if (f1 == NULL || f2 == NULL) {
+ if (f1) fclose(f1);
+ if (f2) fclose(f2);
+ return (0);
+ }
for (;;) {
- n1 = fread(buff1, 1, sizeof(buff1), f1);
- n2 = fread(buff2, 1, sizeof(buff2), f2);
+ n1 = (int)fread(buff1, 1, sizeof(buff1), f1);
+ n2 = (int)fread(buff2, 1, sizeof(buff2), f2);
if (n1 != n2)
break;
if (n1 == 0 && n2 == 0) {
@@ -915,7 +923,7 @@ assertion_file_contents(const char *filename, int line, const void *buff, int s,
return (0);
}
contents = malloc(s * 2);
- n = fread(contents, 1, s * 2, f);
+ n = (int)fread(contents, 1, s * 2, f);
fclose(f);
if (n == s && memcmp(buff, contents, s) == 0) {
free(contents);
@@ -951,9 +959,9 @@ assertion_text_file_contents(const char *filename, int line, const char *buff, c
failure_finish(NULL);
return (0);
}
- s = strlen(buff);
+ s = (int)strlen(buff);
contents = malloc(s * 2 + 128);
- n = fread(contents, 1, s * 2 + 128 - 1, f);
+ n = (int)fread(contents, 1, s * 2 + 128 - 1, f);
if (n >= 0)
contents[n] = '\0';
fclose(f);
@@ -1004,8 +1012,8 @@ assertion_file_contains_lines_any_order(const char *file, int line,
char *buff;
size_t buff_size;
size_t expected_count, actual_count, i, j;
- char **expected;
- char *p, **actual;
+ char **expected = NULL;
+ char *p, **actual = NULL;
char c;
int expected_failure = 0, actual_failure = 0;
@@ -1018,14 +1026,22 @@ assertion_file_contains_lines_any_order(const char *file, int line,
return (0);
}
- /* Make a copy of the provided lines and count up the expected file size. */
- expected_count = 0;
+ /* Make a copy of the provided lines and count up the expected
+ * file size. */
for (i = 0; lines[i] != NULL; ++i) {
}
expected_count = i;
- expected = malloc(sizeof(char *) * expected_count);
- for (i = 0; lines[i] != NULL; ++i) {
- expected[i] = strdup(lines[i]);
+ if (expected_count) {
+ expected = malloc(sizeof(char *) * expected_count);
+ if (expected == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ free(expected);
+ return (0);
+ }
+ for (i = 0; lines[i] != NULL; ++i) {
+ expected[i] = strdup(lines[i]);
+ }
}
/* Break the file into lines */
@@ -1037,11 +1053,19 @@ assertion_file_contains_lines_any_order(const char *file, int line,
++actual_count;
c = *p;
}
- actual = malloc(sizeof(char *) * actual_count);
- for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
- if (*p != '\0') {
- actual[j] = p;
- ++j;
+ if (actual_count) {
+ actual = calloc(sizeof(char *), actual_count);
+ if (actual == NULL) {
+ failure_start(pathname, line, "Can't allocate memory");
+ failure_finish(NULL);
+ free(expected);
+ return (0);
+ }
+ for (j = 0, p = buff; p < buff + buff_size; p += 1 + strlen(p)) {
+ if (*p != '\0') {
+ actual[j] = p;
+ ++j;
+ }
}
}
@@ -1176,11 +1200,11 @@ assertion_file_time(const char *file, int line,
#if defined(_WIN32) && !defined(__CYGWIN__)
#define EPOC_TIME (116444736000000000ULL)
- FILETIME ftime, fbirthtime, fatime, fmtime;
+ FILETIME fxtime, fbirthtime, fatime, fmtime;
ULARGE_INTEGER wintm;
HANDLE h;
- ftime.dwLowDateTime = 0;
- ftime.dwHighDateTime = 0;
+ fxtime.dwLowDateTime = 0;
+ fxtime.dwHighDateTime = 0;
assertion_count(file, line);
/* Note: FILE_FLAG_BACKUP_SEMANTICS applies to open
@@ -1195,9 +1219,9 @@ assertion_file_time(const char *file, int line,
}
r = GetFileTime(h, &fbirthtime, &fatime, &fmtime);
switch (type) {
- case 'a': ftime = fatime; break;
- case 'b': ftime = fbirthtime; break;
- case 'm': ftime = fmtime; break;
+ case 'a': fxtime = fatime; break;
+ case 'b': fxtime = fbirthtime; break;
+ case 'm': fxtime = fmtime; break;
}
CloseHandle(h);
if (r == 0) {
@@ -1205,8 +1229,8 @@ assertion_file_time(const char *file, int line,
failure_finish(NULL);
return (0);
}
- wintm.LowPart = ftime.dwLowDateTime;
- wintm.HighPart = ftime.dwHighDateTime;
+ wintm.LowPart = fxtime.dwLowDateTime;
+ wintm.HighPart = fxtime.dwHighDateTime;
filet = (wintm.QuadPart - EPOC_TIME) / 10000000;
filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100;
nsec = (nsec / 100) * 100; /* Round the request */
@@ -1834,15 +1858,45 @@ canSymlink(void)
return (value);
}
-/*
- * Can this platform run the gzip program?
- */
/* Platform-dependent options for hiding the output of a subcommand. */
#if defined(_WIN32) && !defined(__CYGWIN__)
static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */
#else
static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */
#endif
+/*
+ * Can this platform run the bzip2 program?
+ */
+int
+canBzip2(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("bzip2 -d -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the grzip program?
+ */
+int
+canGrzip(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("grzip -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the gzip program?
+ */
int
canGzip(void)
{
@@ -1856,15 +1910,75 @@ canGzip(void)
}
/*
- * Can this platform run the gunzip program?
+ * Can this platform run the lrzip program?
+ */
+int
+canLrzip(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("lrzip -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the lzip program?
+ */
+int
+canLzip(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("lzip -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the lzma program?
*/
int
-canGunzip(void)
+canLzma(void)
{
static int tested = 0, value = 0;
if (!tested) {
tested = 1;
- if (systemf("gunzip -V %s", redirectArgs) == 0)
+ if (systemf("lzma -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the lzop program?
+ */
+int
+canLzop(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("lzop -V %s", redirectArgs) == 0)
+ value = 1;
+ }
+ return (value);
+}
+
+/*
+ * Can this platform run the xz program?
+ */
+int
+canXz(void)
+{
+ static int tested = 0, value = 0;
+ if (!tested) {
+ tested = 1;
+ if (systemf("xz -V %s", redirectArgs) == 0)
value = 1;
}
return (value);
@@ -2124,7 +2238,7 @@ is_LargeInode(const char *file)
/* Use "list.h" to create a list of all tests (functions and names). */
#undef DEFINE_TEST
#define DEFINE_TEST(n) { n, #n, 0 },
-struct { void (*func)(void); const char *name; int failures; } tests[] = {
+struct test_list_t tests[] = {
#include "list.h"
};
@@ -2377,65 +2491,6 @@ success:
return strdup(buff);
}
-static int
-get_test_set(int *test_set, int limit, const char *test)
-{
- int start, end;
- int idx = 0;
-
- if (test == NULL) {
- /* Default: Run all tests. */
- for (;idx < limit; idx++)
- test_set[idx] = idx;
- return (limit);
- }
- if (*test >= '0' && *test <= '9') {
- const char *vp = test;
- start = 0;
- while (*vp >= '0' && *vp <= '9') {
- start *= 10;
- start += *vp - '0';
- ++vp;
- }
- if (*vp == '\0') {
- end = start;
- } else if (*vp == '-') {
- ++vp;
- if (*vp == '\0') {
- end = limit - 1;
- } else {
- end = 0;
- while (*vp >= '0' && *vp <= '9') {
- end *= 10;
- end += *vp - '0';
- ++vp;
- }
- }
- } else
- return (-1);
- if (start < 0 || end >= limit || start > end)
- return (-1);
- while (start <= end)
- test_set[idx++] = start++;
- } else {
- size_t len = strlen(test);
- for (start = 0; start < limit; ++start) {
- const char *name = tests[start].name;
- const char *p;
-
- while ((p = strchr(name, test[0])) != NULL) {
- if (strncmp(p, test, len) == 0) {
- test_set[idx++] = start;
- break;
- } else
- name = p + 1;
- }
-
- }
- }
- return ((idx == 0)?-1:idx);
-}
-
int
main(int argc, char **argv)
{
@@ -2720,10 +2775,11 @@ main(int argc, char **argv)
do {
int test_num;
- test_num = get_test_set(test_set, limit, *argv);
+ test_num = get_test_set(test_set, limit, *argv, tests);
if (test_num < 0) {
printf("*** INVALID Test %s\n", *argv);
free(refdir_alloc);
+ free(testprogdir);
usage(progname);
return (1);
}
diff --git a/contrib/libarchive/tar/test/test.h b/contrib/libarchive/tar/test/test.h
index 4c6e9cb..74c85f2 100644
--- a/contrib/libarchive/tar/test/test.h
+++ b/contrib/libarchive/tar/test/test.h
@@ -268,11 +268,29 @@ void sleepUntilAfter(time_t);
/* Return true if this platform can create symlinks. */
int canSymlink(void);
+/* Return true if this platform can run the "bzip2" program. */
+int canBzip2(void);
+
+/* Return true if this platform can run the "grzip" program. */
+int canGrzip(void);
+
/* Return true if this platform can run the "gzip" program. */
int canGzip(void);
-/* Return true if this platform can run the "gunzip" program. */
-int canGunzip(void);
+/* Return true if this platform can run the "lrzip" program. */
+int canLrzip(void);
+
+/* Return true if this platform can run the "lzip" program. */
+int canLzip(void);
+
+/* Return true if this platform can run the "lzma" program. */
+int canLzma(void);
+
+/* Return true if this platform can run the "lzop" program. */
+int canLzop(void);
+
+/* Return true if this platform can run the "xz" program. */
+int canXz(void);
/* Return true if this filesystem can handle nodump flags. */
int canNodump(void);
diff --git a/contrib/libarchive/tar/test/test_copy.c b/contrib/libarchive/tar/test/test_copy.c
index 5a1c4d0..6890d1a 100644
--- a/contrib/libarchive/tar/test/test_copy.c
+++ b/contrib/libarchive/tar/test/test_copy.c
@@ -29,6 +29,9 @@ __FBSDID("$FreeBSD$");
# include <limits.h>
# include <sys/cygwin.h>
#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# include <direct.h>
+#endif
/*
* Try to figure out how deep we can go in our tests. Assumes that
@@ -119,7 +122,7 @@ compute_filenames(void)
if (i > 9) {
buff[j--] = '0' + ((i / 10) % 10);
if (i > 99)
- buff[j--] = '0' + (i / 100);
+ buff[j--] = '0' + (char)(i / 100);
}
buff[j] = '_';
/* Guard against obvious screwups in the above code. */
@@ -202,7 +205,7 @@ verify_tree(size_t limit)
sprintf(name1, "f/%s", filenames[i]);
if (i <= limit) {
assertFileExists(name1);
- assertFileContents(name1, strlen(name1), name1);
+ assertFileContents(name1, (int)strlen(name1), name1);
}
sprintf(name2, "l/%s", filenames[i]);
diff --git a/contrib/libarchive/tar/test/test_extract.tar.Z.uu b/contrib/libarchive/tar/test/test_extract.tar.Z.uu
new file mode 100644
index 0000000..92713a5
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.Z.uu
@@ -0,0 +1,9 @@
+begin 664 test_extract.tar.Z
+M'YV09M*P*1,#@,&#"!,J7,BPH<.'$",BA$'1A@T:(`!0C'&C!HR,&SM^U$BQ
+M9$D9,T#$D`%CAHP;-&"@Q`@C1HP9-FH```%#HL^?0(,*!5!G#ITP<DB.J5-F
+M:,.E39TN-$D1)-6,4K-JW<JUZ]`Q;]S0*2-V#H@W9D`$'!C#A0*O<./*G4NW
+MKMV[>//JW<O7X=HR,OH*=EC2(D:2'#U:33R2JDF4*EFZA"F31@V>-F?<Z,ES
+ML.>'18\FI0@5;FFOCJV:Q/JYM>NM8,62I6,6K5J!@-V^WLV[M^_?P(,+'TZ\
+0N/'CR),K7\Z\N?/GT*,K!P``
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.bz2.uu b/contrib/libarchive/tar/test/test_extract.tar.bz2.uu
new file mode 100644
index 0000000..9a37413
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.bz2.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.tar.bz2
+M0EIH.3%!629368N]6:```'U[D=(0`"!``7^```AK)9X`!```$0`(,`"X#&$Q
+M,F`F``,83$R8"8``*J:")M0TCQ30-/%-3*]V3EE!&(DSM8?BJ4J)=TSJ4/"B
+M,?#R_6>?9K=+H02NT0V040P3.SHF:(573*)M5&;!-%6RO=6F5":N"+,"YZ;L
+AV+<]%F[GWYCR<%FRKAPR=7VY+'+1)_B[DBG"A(1=ZLT`
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.grz.uu b/contrib/libarchive/tar/test/test_extract.tar.grz.uu
new file mode 100644
index 0000000..44651e1
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.grz.uu
@@ -0,0 +1,7 @@
+begin 644 test_extract.tar.grz
+M1U)::7!)20`"!#HI``P``*P,``#U````SP```'<````[-=0OM"R^UP#^C?Z<
+MFGU0]I:>SW7]H01)1\WY:59("M_=V4[N[R*'`H&:'E=O@5B(?T,0?@)%-:_D
+M;EUP)!JVN)@V_:ABYS3+[[6/R(NU,-::]'X&;,]:,HR[*3#R!@:W)IGC`,&G
+8L+IZ7]FP=8U_R?CZ2XPO)"H-ME3@P]$`
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.gz.uu b/contrib/libarchive/tar/test/test_extract.tar.gz.uu
new file mode 100644
index 0000000..19f8bc0
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.gz.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.tar.gz
+M'XL(""S!:U```W1E<W1?97AT<F%C="YT87(`2\O,235DH"TP,#`P,S-1`-*&
+MYJ8&R#04&!DK&!H9&!N9FP"9)@H&AH;&9J8,"@8T=A<8E!:7)!8!G9)<FHI7
+M'2%YB$\4X/00`<GY>26I>27%"OEI"FF@M*#'-=!.&@5T!*`X-Z*Q'23E?Q-3
+A</XW-QC-__0`Z/G?:#3_CX)1,`I&P8@```&.A<``#```
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.lrz.uu b/contrib/libarchive/tar/test/test_extract.tar.lrz.uu
new file mode 100644
index 0000000..a2621f4
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.lrz.uu
@@ -0,0 +1,9 @@
+begin 664 test_extract.tar.lrz
+M3%):20`&``P``````````%T````!`0```@$`$`,`````#@`#`````$P``S<`
+M-P`````5``%/`!```#H``6,``0``6``!IP`!```%`@%/`/`#`3T```0`"0`!
+M=@$`!`#P!0```(5'8Z<&<`"E"````#,:2=:X2EY$(`=+>P?_D@0*H:&)P-5?
+MZX%NI60,IT@(N<,S%?7H2TLP5)FN#[-;&&[/2A#BNH4(7#C+*&ZP<>K&B)AG
+M:Z(;Y=]3<5Q$)_[[5M\7=]N7A$%\ZF:H2/,Q%BK$JA4L!,K(-RZU2X[/`%69
+.9U@/B[!N",NH4]8F,M(`
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.lz.uu b/contrib/libarchive/tar/test/test_extract.tar.lz.uu
new file mode 100644
index 0000000..cb380e3
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.lz.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.tar.lz
+M3%I)4`$,`#,:2=:X2EY2J/TZ6]L7]]N4K?J&A)E2#"A'E"T1EP+MU&;(P1FY
+MV\,8BTS,N0/O2=#67;G5)%I'C,D.U?*T!NX("FYPYI9I40F>X))?^8\?E?#>
+MOP";"GD#8(9*K;XP318H<O&!L/<?HIOYPSNA8V5:E"239/Z<6[6>XZ\?_^SZ
+6K-(!CH7```P```````"=````````````
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.lzma.uu b/contrib/libarchive/tar/test/test_extract.tar.lzma.uu
new file mode 100644
index 0000000..581236a
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.lzma.uu
@@ -0,0 +1,7 @@
+begin 664 test_extract.tar.lzma
+M70``@`#__________P`S&DG6N$I>4JC].EO;%_?;E*WZAH294@PH1Y0M$9<"
+M[=1FR,$9N=O#&(M,Q24U'H+5Z^7^*J;G!)OU]O'2D;AZ&0^IO?>-YA]$:-X_
+MD^O)YVM(4`^-MT$X`.D(6)*$]3HNB9KJ_H=1$QKYZ:`:,H_L"H[#"?#Z5A<]
+%O_OZW=D`
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.lzo.uu b/contrib/libarchive/tar/test/test_extract.tar.lzo.uu
new file mode 100644
index 0000000..29dd8d8
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.lzo.uu
@@ -0,0 +1,9 @@
+begin 664 test_extract.tar.lzo
+MB4Q:3P`-"AH*$#`@8`E``04#```!``"!M%!R@T``````$'1E<W1?97AT<F%C
+M="YT87*FJ0IM```,`````+BYG#.C`V9I;&4Q`"`]```+,#`P-C8T(``P,#$W
+M-3`J'0`PH```!C(S(#$R,#,R-S0P,C,T(#`Q,3,V-0`@,"`]6`*T"PAU<W1A
+M<@`P,&-U9:`"-10`/GP`I!EP&V4!(#44`2!P6``)8V]N=&5N=',@;V8@CD$N
+M"B!PC`(@`#Q``FT^,B`^@`4@#/X/-#6>?S<P(`!6_0\R(`#/_`\@/N@/(```
+=`')X`0X``````````````````````!$`````````
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract.tar.xz.uu b/contrib/libarchive/tar/test/test_extract.tar.xz.uu
new file mode 100644
index 0000000..24cac6c
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract.tar.xz.uu
@@ -0,0 +1,8 @@
+begin 664 test_extract.tar.xz
+M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`O_`'E=`#,:2=:X2EY2J/TZ6]L7
+M]]N4K?J&A)E2#"A'E"T1EP+MU&;(P1FYV\,8BTS%)34>@M7KY?XJIN<$F_7V
+M\=*1N'H9#ZF]]XWF'T1HWC^3Z\GG:TA0#XVW03@`Z0A8DH3U.BZ)FNK^AU$3
+M&OGIH!HRC^P*CL,)\/,MGP``````2IVA+$<(^YX``94!@!@``&X^\DRQQ&?[
+(`@`````$65H`
+`
+end
diff --git a/contrib/libarchive/tar/test/test_extract_tar_Z.c b/contrib/libarchive/tar/test/test_extract_tar_Z.c
new file mode 100644
index 0000000..7c994b4
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_Z.c
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_Z)
+{
+ const char *reffile = "test_extract.tar.Z";
+
+ extract_reference_file(reffile);
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_bz2.c b/contrib/libarchive/tar/test/test_extract_tar_bz2.c
new file mode 100644
index 0000000..b734dd2
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_bz2.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_bz2)
+{
+ const char *reffile = "test_extract.tar.bz2";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canBzip2()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems bzip2 is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_grz.c b/contrib/libarchive/tar/test/test_extract_tar_grz.c
new file mode 100644
index 0000000..9c0615e
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_grz.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_grz)
+{
+ const char *reffile = "test_extract.tar.grz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canGrzip()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems grzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_gz.c b/contrib/libarchive/tar/test/test_extract_tar_gz.c
new file mode 100644
index 0000000..2fdb4ba
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_gz.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_gz)
+{
+ const char *reffile = "test_extract.tar.gz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canGzip()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems gzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_lrz.c b/contrib/libarchive/tar/test/test_extract_tar_lrz.c
new file mode 100644
index 0000000..56a0fb8
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_lrz.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_lrz)
+{
+ const char *reffile = "test_extract.tar.lrz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLrzip()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems lrzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_lz.c b/contrib/libarchive/tar/test/test_extract_tar_lz.c
new file mode 100644
index 0000000..5ec7e9a
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_lz.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_lz)
+{
+ const char *reffile = "test_extract.tar.lz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLzip()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems lzip is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_lzma.c b/contrib/libarchive/tar/test/test_extract_tar_lzma.c
new file mode 100644
index 0000000..2fa2af0
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_lzma.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_lzma)
+{
+ const char *reffile = "test_extract.tar.lzma";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLzma()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems lzma is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_lzo.c b/contrib/libarchive/tar/test/test_extract_tar_lzo.c
new file mode 100644
index 0000000..17b4295
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_lzo.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_lzo)
+{
+ const char *reffile = "test_extract.tar.lzo";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canLzop()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems lzop is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_extract_tar_xz.c b/contrib/libarchive/tar/test/test_extract_tar_xz.c
new file mode 100644
index 0000000..860bab7
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_extract_tar_xz.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_extract_tar_xz)
+{
+ const char *reffile = "test_extract.tar.xz";
+ int f;
+
+ extract_reference_file(reffile);
+ f = systemf("%s -tf %s >test.out 2>test.err", testprog, reffile);
+ if (f == 0 || canXz()) {
+ assertEqualInt(0, systemf("%s -xf %s >test.out 2>test.err",
+ testprog, reffile));
+
+ assertFileExists("file1");
+ assertTextFileContents("contents of file1.\n", "file1");
+ assertFileExists("file2");
+ assertTextFileContents("contents of file2.\n", "file2");
+ assertEmptyFile("test.out");
+ assertEmptyFile("test.err");
+ } else {
+ skipping("It seems xz is not supported on this platform");
+ }
+}
diff --git a/contrib/libarchive/tar/test/test_option_a.c b/contrib/libarchive/tar/test/test_option_a.c
new file mode 100644
index 0000000..a000621
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_a.c
@@ -0,0 +1,110 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_a)
+{
+ size_t s;
+ char *p;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Test1: archive it with .tar.Z suffix. */
+ assertEqualInt(0,
+ systemf("%s -acf test1.tar.Z f 2>test1.err", testprog));
+ assertEmptyFile("test1.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test1.tar.Z");
+ assert(s > 2);
+ failure("The archive should be compressed");
+ assertEqualMem(p, "\x1f\x9d", 2);
+
+ /* Test2: archive it with .taZ suffix. */
+ assertEqualInt(0,
+ systemf("%s -acf test2.taZ f 2>test2.err", testprog));
+ assertEmptyFile("test2.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test2.taZ");
+ assert(s > 2);
+ failure("The archive should be compressed");
+ assertEqualMem(p, "\x1f\x9d", 2);
+
+ /* Test3: archive it with .tar.Z.uu suffix. */
+ assertEqualInt(0,
+ systemf("%s -acf test3.tar.Z.uu f 2>test3.err", testprog));
+ assertEmptyFile("test3.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test3.tar.Z.uu");
+ assert(s > 12);
+ failure("The archive should be uuencoded");
+ assertEqualMem(p, "begin 644 -\n", 12);
+
+ /* Test4: archive it with .zip suffix. */
+ assertEqualInt(0,
+ systemf("%s -acf test4.zip f 2>test4.err", testprog));
+ assertEmptyFile("test4.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test4.zip");
+ assert(s > 4);
+ failure("The archive should be zipped");
+ assertEqualMem(p, "\x50\x4b\x03\x04", 4);
+
+ /* Test5: archive it with .tar.Z suffix and --uuencode option. */
+ assertEqualInt(0,
+ systemf("%s -acf test5.tar.Z --uuencode f 2>test5.err",
+ testprog));
+ assertEmptyFile("test5.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test5.tar.Z");
+ assert(s > 2);
+ failure("The archive should be compressed, ignoring --uuencode option");
+ assertEqualMem(p, "\x1f\x9d", 2);
+
+ /* Test6: archive it with .xxx suffix(unknown suffix) and
+ * --uuencode option. */
+ assertEqualInt(0,
+ systemf("%s -acf test6.xxx --uuencode f 2>test6.err",
+ testprog));
+ assertEmptyFile("test6.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test6.xxx");
+ assert(s > 12);
+ failure("The archive should be uuencoded");
+ assertEqualMem(p, "begin 644 -\n", 12);
+
+ /* Test7: archive it with .tar.Z suffix using a long-name option. */
+ assertEqualInt(0,
+ systemf("%s --auto-compress -cf test7.tar.Z f 2>test7.err",
+ testprog));
+ assertEmptyFile("test7.err");
+ /* Check that the archive file has a compress signature. */
+ p = slurpfile(&s, "test7.tar.Z");
+ assert(s > 2);
+ failure("The archive should be compressed");
+ assertEqualMem(p, "\x1f\x9d", 2);
+}
diff --git a/contrib/libarchive/tar/test/test_option_b64encode.c b/contrib/libarchive/tar/test/test_option_b64encode.c
new file mode 100644
index 0000000..1e7c571
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_b64encode.c
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_b64encode)
+{
+ char *p;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with compress compression and uuencode. */
+ assertEqualInt(0,
+ systemf("%s -cf - -Z --b64encode f >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin-base64 644", 16);
+
+ /* Archive it with uuencode only. */
+ assertEqualInt(0,
+ systemf("%s -cf - --b64encode f >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin-base64 644", 16);
+}
diff --git a/contrib/libarchive/tar/test/test_option_grzip.c b/contrib/libarchive/tar/test/test_option_grzip.c
new file mode 100644
index 0000000..5132eee
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_grzip.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_grzip)
+{
+ char *p;
+ size_t s;
+
+ if (!canGrzip()) {
+ skipping("grzip is not supported on this platform");
+ return;
+ }
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with grzip compression. */
+ assertEqualInt(0,
+ systemf("%s -cf - --grzip f >archive.out 2>archive.err",
+ testprog));
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ /* Check that the archive file has an grzip signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "GRZipII\x00\x02\x04:)", 12);
+}
diff --git a/contrib/libarchive/tar/test/test_option_j.c b/contrib/libarchive/tar/test/test_option_j.c
new file mode 100644
index 0000000..3202c3b
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_j.c
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_j)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with bzip2 compression. */
+ r = systemf("%s -jcf archive.out f 2>archive.err", testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (!canBzip2()) {
+ skipping("bzip2 is not supported on this platform");
+ return;
+ }
+ failure("-j option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ assertEmptyFile("archive.err");
+ /* Check that the archive file has a bzip2 signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "BZh9", 4);
+}
diff --git a/contrib/libarchive/tar/test/test_option_lrzip.c b/contrib/libarchive/tar/test/test_option_lrzip.c
new file mode 100644
index 0000000..d3486a3
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_lrzip.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_lrzip)
+{
+ char *p;
+ size_t s;
+
+ if (!canLrzip()) {
+ skipping("lrzip is not supported on this platform");
+ return;
+ }
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lrzip compression. */
+ assertEqualInt(0,
+ systemf("%s -cf - --lrzip f >archive.out 2>archive.err",
+ testprog));
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "LRZI\x00", 5);
+}
diff --git a/contrib/libarchive/tar/test/test_option_lzma.c b/contrib/libarchive/tar/test/test_option_lzma.c
new file mode 100644
index 0000000..a845666
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_lzma.c
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_lzma)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lzma compression. */
+ r = systemf("%s -cf - --lzma f >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "Unsupported compression") != NULL) {
+ skipping("This version of bsdtar was compiled "
+ "without lzma support");
+ return;
+ }
+ failure("--lzma option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x5d\00\00", 3);
+}
diff --git a/contrib/libarchive/tar/test/test_option_lzop.c b/contrib/libarchive/tar/test/test_option_lzop.c
new file mode 100644
index 0000000..1145499
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_lzop.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_lzop)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with lzop compression. */
+ r = systemf("%s -cf - --lzop f >archive.out 2>archive.err", testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (!canLzop()) {
+ skipping("lzop is not supported on this platform");
+ return;
+ }
+ failure("--lzop option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an lzma signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 9);
+}
diff --git a/contrib/libarchive/tar/test/test_option_newer_than.c b/contrib/libarchive/tar/test/test_option_newer_than.c
index c9432dc..2a5fe04 100644
--- a/contrib/libarchive/tar/test/test_option_newer_than.c
+++ b/contrib/libarchive/tar/test/test_option_newer_than.c
@@ -48,8 +48,11 @@ DEFINE_TEST(test_option_newer_than)
assertMakeFile("a/b/new.txt", 0644, "new file in old directory");
/* Test --newer-than on create */
- assertEqualInt(0, systemf("%s -cf ../test1.tar --newer-than middle.txt *.txt a", testprog));
- assertEqualInt(0, systemf("%s -cf ../test2.tar *.txt a", testprog));
+ assertEqualInt(0,
+ systemf("%s --format pax -cf ../test1.tar "
+ "--newer-than middle.txt *.txt a", testprog));
+ assertEqualInt(0,
+ systemf("%s --format pax -cf ../test2.tar *.txt a", testprog));
assertChdir("..");
/* Extract test1.tar to a clean dir and verify what got archived. */
diff --git a/contrib/libarchive/tar/test/test_option_older_than.c b/contrib/libarchive/tar/test/test_option_older_than.c
new file mode 100644
index 0000000..4bdd2ed
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_older_than.c
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 2010 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_older_than)
+{
+ struct stat st;
+
+ /*
+ * Basic test of --older-than.
+ * First, create three files with different mtimes.
+ * Create test1.tar with --older-than, test2.tar without.
+ */
+ assertMakeDir("test1in", 0755);
+ assertChdir("test1in");
+ assertMakeDir("a", 0755);
+ assertMakeDir("a/b", 0755);
+ assertMakeFile("old.txt", 0644, "old.txt");
+ assertMakeFile("a/b/old.txt", 0644, "old file in old directory");
+ assertEqualInt(0, stat("old.txt", &st));
+ sleepUntilAfter(st.st_mtime);
+ assertMakeFile("middle.txt", 0644, "middle.txt");
+ assertEqualInt(0, stat("middle.txt", &st));
+ sleepUntilAfter(st.st_mtime);
+ assertMakeFile("new.txt", 0644, "new");
+ assertMakeFile("a/b/new.txt", 0644, "new file in old directory");
+
+ /* Test --older-than on create */
+ assertEqualInt(0,
+ systemf("%s --format pax -cf ../test1.tar "
+ "--older-than middle.txt *.txt a",
+ testprog));
+ assertEqualInt(0,
+ systemf("%s --format pax -cf ../test2.tar *.txt a",
+ testprog));
+ assertChdir("..");
+
+ /* Extract test1.tar to a clean dir and verify what got archived. */
+ assertMakeDir("test1out", 0755);
+ assertChdir("test1out");
+ assertEqualInt(0, systemf("%s xf ../test1.tar", testprog));
+ assertFileNotExists("new.txt");
+ assertFileNotExists("a/b/new.txt");
+ assertFileNotExists("middle.txt");
+ assertFileExists("old.txt");
+ assertFileExists("a/b/old.txt");
+ assertChdir("..");
+
+ /* Extract test2.tar to a clean dir with --older-than and verify. */
+ assertMakeDir("test2out", 0755);
+ assertChdir("test2out");
+ assertEqualInt(0,
+ systemf("%s xf ../test2.tar --older-than ../test1in/middle.txt",
+ testprog));
+ assertFileNotExists("new.txt");
+ assertFileNotExists("a/b/new.txt");
+ assertFileNotExists("middle.txt");
+ assertFileExists("old.txt");
+ assertFileExists("a/b/old.txt");
+ assertChdir("..");
+}
diff --git a/contrib/libarchive/tar/test/test_option_r.c b/contrib/libarchive/tar/test/test_option_r.c
index 70c2087..7787685 100644
--- a/contrib/libarchive/tar/test/test_option_r.c
+++ b/contrib/libarchive/tar/test/test_option_r.c
@@ -60,6 +60,11 @@ DEFINE_TEST(test_option_r)
/* Edit that file with a lot more data and update the archive with a new copy. */
buff = malloc(buff_size);
assert(buff != NULL);
+ if (buff == NULL) {
+ free(p0);
+ return;
+ }
+
for (i = 0; i < (int)buff_size; ++i)
buff[i] = "abcdefghijklmnopqrstuvwxyz"[rand() % 26];
buff[buff_size - 1] = '\0';
@@ -126,5 +131,5 @@ DEFINE_TEST(test_option_r)
assertEmptyFile("extract.err");
/* Verify that the second copy of f1 overwrote the first. */
- assertFileContents(buff, strlen(buff), "f1");
+ assertFileContents(buff, (int)strlen(buff), "f1");
}
diff --git a/contrib/libarchive/tar/test/test_option_uuencode.c b/contrib/libarchive/tar/test/test_option_uuencode.c
new file mode 100644
index 0000000..cdc6bab
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_uuencode.c
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_uuencode)
+{
+ char *p;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with compress compression and uuencode. */
+ assertEqualInt(0,
+ systemf("%s -cf - -Z --uuencode f >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin 644", 9);
+
+ /* Archive it with uuencode only. */
+ assertEqualInt(0,
+ systemf("%s -cf - --uuencode f >archive.out 2>archive.err",
+ testprog));
+ /* Check that the archive file has an uuencode signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "begin 644", 9);
+}
diff --git a/contrib/libarchive/tar/test/test_option_xz.c b/contrib/libarchive/tar/test/test_option_xz.c
new file mode 100644
index 0000000..7387a60
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_xz.c
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_xz)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with xz compression. */
+ r = systemf("%s -cf - --xz f >archive.out 2>archive.err",
+ testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (strstr(p, "Unsupported compression") != NULL) {
+ skipping("This version of bsdtar was compiled "
+ "without xz support");
+ return;
+ }
+ failure("--xz option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has an xz signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 2);
+ assertEqualMem(p, "\xFD\x37\x7A\x58\x5A\x00", 6);
+}
diff --git a/contrib/libarchive/tar/test/test_option_z.c b/contrib/libarchive/tar/test/test_option_z.c
new file mode 100644
index 0000000..1f952ab
--- /dev/null
+++ b/contrib/libarchive/tar/test/test_option_z.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_option_z)
+{
+ char *p;
+ int r;
+ size_t s;
+
+ /* Create a file. */
+ assertMakeFile("f", 0644, "a");
+
+ /* Archive it with gzip compression. */
+ r = systemf("%s -zcf archive.out f 2>archive.err", testprog);
+ p = slurpfile(&s, "archive.err");
+ p[s] = '\0';
+ if (r != 0) {
+ if (!canGzip()) {
+ skipping("gzip is not supported on this platform");
+ return;
+ }
+ failure("-z option is broken");
+ assertEqualInt(r, 0);
+ return;
+ }
+ /* Check that the archive file has a gzip signature. */
+ p = slurpfile(&s, "archive.out");
+ assert(s > 4);
+ assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
+}
diff --git a/contrib/libarchive/tar/test/test_stdio.c b/contrib/libarchive/tar/test/test_stdio.c
index 1780d96..8d44dd6 100644
--- a/contrib/libarchive/tar/test/test_stdio.c
+++ b/contrib/libarchive/tar/test/test_stdio.c
@@ -113,7 +113,7 @@ DEFINE_TEST(test_stdio)
assertEqualInt(r, 0);
/* Verify xvOf.out is the file contents */
p = slurpfile(&s, "xvOf.out");
- assert(s = 3);
+ assertEqualInt((int)s, 3);
assertEqualMem(p, "abc", 3);
/* TODO: Verify xvf.err */
diff --git a/contrib/libarchive/tar/util.c b/contrib/libarchive/tar/util.c
index 6112840..a6f3189 100644
--- a/contrib/libarchive/tar/util.c
+++ b/contrib/libarchive/tar/util.c
@@ -120,14 +120,12 @@ safe_fprintf(FILE *f, const char *fmt, ...)
fmtbuff_length = length+1;
else if (fmtbuff_length < 8192)
fmtbuff_length *= 2;
- else {
- int old_length = fmtbuff_length;
+ else if (fmtbuff_length < 1000000)
fmtbuff_length += fmtbuff_length / 4;
- if (old_length > fmtbuff_length) {
- length = old_length;
- fmtbuff_heap[length-1] = '\0';
- break;
- }
+ else {
+ length = fmtbuff_length;
+ fmtbuff_heap[length-1] = '\0';
+ break;
}
free(fmtbuff_heap);
fmtbuff_heap = malloc(fmtbuff_length);
@@ -148,7 +146,12 @@ safe_fprintf(FILE *f, const char *fmt, ...)
/* Note: mbrtowc() has a cleaner API, but mbtowc() seems a bit
* more portable, so we use that here instead. */
- n = mbtowc(NULL, NULL, 1); /* Reset the shift state. */
+ if (mbtowc(NULL, NULL, 1) == -1) { /* Reset the shift state. */
+ /* mbtowc() should never fail in practice, but
+ * handle the theoretical error anyway. */
+ free(fmtbuff_heap);
+ return;
+ }
/* Write data, expanding unprintable characters. */
p = fmtbuff;
@@ -188,8 +191,7 @@ safe_fprintf(FILE *f, const char *fmt, ...)
fprintf(f, "%s", outbuff);
/* If we allocated a heap-based formatting buffer, free it now. */
- if (fmtbuff_heap != NULL)
- free(fmtbuff_heap);
+ free(fmtbuff_heap);
}
/*
@@ -380,7 +382,7 @@ int
edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
{
const char *name = archive_entry_pathname(entry);
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
char *subst_name;
int r;
diff --git a/contrib/libarchive/tar/write.c b/contrib/libarchive/tar/write.c
index e5307c8..82f47db 100644
--- a/contrib/libarchive/tar/write.c
+++ b/contrib/libarchive/tar/write.c
@@ -131,13 +131,79 @@ seek_file(int fd, int64_t offset, int whence)
#define open _open
#define close _close
#define read _read
+#ifdef lseek
+#undef lseek
+#endif
#define lseek seek_file
#endif
+static void
+set_writer_options(struct bsdtar *bsdtar, struct archive *a)
+{
+ const char *writer_options;
+ int r;
+
+ writer_options = getenv(ENV_WRITER_OPTIONS);
+ if (writer_options != NULL) {
+ char *p;
+ /* Set default write options. */
+ p = malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
+ + strlen(writer_options) + 1);
+ if (p == NULL)
+ lafe_errc(1, errno, "Out of memory");
+ /* Prepend magic code to ignore options for
+ * a format or filters which are not added to
+ * the archive write object. */
+ strncpy(p, IGNORE_WRONG_MODULE_NAME,
+ sizeof(IGNORE_WRONG_MODULE_NAME) -1);
+ strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, writer_options);
+ r = archive_write_set_options(a, p);
+ free(p);
+ if (r < ARCHIVE_WARN)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ else
+ archive_clear_error(a);
+ }
+ if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+}
+
+static void
+set_reader_options(struct bsdtar *bsdtar, struct archive *a)
+{
+ const char *reader_options;
+ int r;
+
+ (void)bsdtar; /* UNUSED */
+
+ reader_options = getenv(ENV_READER_OPTIONS);
+ if (reader_options != NULL) {
+ char *p;
+ /* Set default write options. */
+ p = malloc(sizeof(IGNORE_WRONG_MODULE_NAME)
+ + strlen(reader_options) + 1);
+ if (p == NULL)
+ lafe_errc(1, errno, "Out of memory");
+ /* Prepend magic code to ignore options for
+ * a format or filters which are not added to
+ * the archive write object. */
+ strncpy(p, IGNORE_WRONG_MODULE_NAME,
+ sizeof(IGNORE_WRONG_MODULE_NAME) -1);
+ strcpy(p + sizeof(IGNORE_WRONG_MODULE_NAME) -1, reader_options);
+ r = archive_read_set_options(a, p);
+ free(p);
+ if (r < ARCHIVE_WARN)
+ lafe_errc(1, 0, "%s", archive_error_string(a));
+ else
+ archive_clear_error(a);
+ }
+}
+
void
tar_mode_c(struct bsdtar *bsdtar)
{
struct archive *a;
+ const void *filter_name;
int r;
if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL)
@@ -146,15 +212,16 @@ tar_mode_c(struct bsdtar *bsdtar)
a = archive_write_new();
/* Support any format that the library supports. */
- if (bsdtar->create_format == NULL) {
+ if (cset_get_format(bsdtar->cset) == NULL) {
r = archive_write_set_format_pax_restricted(a);
- bsdtar->create_format = "pax restricted";
+ cset_set_format(bsdtar->cset, "pax restricted");
} else {
- r = archive_write_set_format_by_name(a, bsdtar->create_format);
+ r = archive_write_set_format_by_name(a,
+ cset_get_format(bsdtar->cset));
}
if (r != ARCHIVE_OK) {
fprintf(stderr, "Can't use format %s: %s\n",
- bsdtar->create_format,
+ cset_get_format(bsdtar->cset),
archive_error_string(a));
usage();
}
@@ -162,46 +229,14 @@ tar_mode_c(struct bsdtar *bsdtar)
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);
- } else {
- switch (bsdtar->create_compression) {
- case 0:
- r = ARCHIVE_OK;
- break;
- case 'j': case 'y':
- r = archive_write_set_compression_bzip2(a);
- break;
- case 'J':
- r = archive_write_set_compression_xz(a);
- break;
- case OPTION_LZIP:
- r = archive_write_set_compression_lzip(a);
- break;
- case OPTION_LZMA:
- r = archive_write_set_compression_lzma(a);
- break;
- case 'z':
- r = archive_write_set_compression_gzip(a);
- break;
- case 'Z':
- r = archive_write_set_compression_compress(a);
- break;
- default:
- lafe_errc(1, 0,
- "Unrecognized compression option -%c",
- bsdtar->create_compression);
- }
- if (r != ARCHIVE_OK) {
- lafe_errc(1, 0,
- "Unsupported compression option -%c",
- bsdtar->create_compression);
- }
+ r = cset_write_add_filters(bsdtar->cset, a, &filter_name);
+ if (r < ARCHIVE_WARN) {
+ lafe_errc(1, 0, "Unsupported compression option --%s",
+ (const char *)filter_name);
}
- if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options))
- lafe_errc(1, 0, "%s", archive_error_string(a));
- if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename))
+ set_writer_options(bsdtar, a);
+ if (ARCHIVE_OK != archive_write_open_filename(a, bsdtar->filename))
lafe_errc(1, 0, "%s", archive_error_string(a));
write_archive(a, bsdtar);
}
@@ -238,13 +273,14 @@ tar_mode_r(struct bsdtar *bsdtar)
archive_read_support_format_empty(a);
archive_read_support_format_tar(a);
archive_read_support_format_gnutar(a);
+ set_reader_options(bsdtar, a);
r = archive_read_open_fd(a, bsdtar->fd, 10240);
if (r != ARCHIVE_OK)
lafe_errc(1, archive_errno(a),
"Can't read archive %s: %s", bsdtar->filename,
archive_error_string(a));
while (0 == archive_read_next_header(a, &entry)) {
- if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) {
+ if (archive_filter_code(a, 0) != ARCHIVE_FILTER_NONE) {
archive_read_free(a);
close(bsdtar->fd);
lafe_errc(1, 0,
@@ -267,17 +303,17 @@ tar_mode_r(struct bsdtar *bsdtar)
* of arcane ugliness.
*/
- if (bsdtar->create_format != NULL) {
+ if (cset_get_format(bsdtar->cset) != NULL) {
/* If the user requested a format, use that, but ... */
archive_write_set_format_by_name(a,
- bsdtar->create_format);
+ cset_get_format(bsdtar->cset));
/* ... complain if it's not compatible. */
format &= ARCHIVE_FORMAT_BASE_MASK;
if (format != (int)(archive_format(a) & ARCHIVE_FORMAT_BASE_MASK)
&& format != ARCHIVE_FORMAT_EMPTY) {
lafe_errc(1, 0,
"Format %s is incompatible with the archive %s.",
- bsdtar->create_format, bsdtar->filename);
+ cset_get_format(bsdtar->cset), bsdtar->filename);
}
} else {
/*
@@ -290,8 +326,7 @@ tar_mode_r(struct bsdtar *bsdtar)
}
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))
- lafe_errc(1, 0, "%s", archive_error_string(a));
+ set_writer_options(bsdtar, a);
if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
lafe_errc(1, 0, "%s", archive_error_string(a));
@@ -328,6 +363,7 @@ tar_mode_u(struct bsdtar *bsdtar)
archive_read_support_filter_all(a);
archive_read_support_format_tar(a);
archive_read_support_format_gnutar(a);
+ set_reader_options(bsdtar, a);
if (archive_read_open_fd(a, bsdtar->fd, bsdtar->bytes_per_block)
!= ARCHIVE_OK) {
lafe_errc(1, 0,
@@ -337,7 +373,7 @@ tar_mode_u(struct bsdtar *bsdtar)
/* Build a list of all entries and their recorded mod times. */
while (0 == archive_read_next_header(a, &entry)) {
- if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) {
+ if (archive_filter_code(a, 0) != ARCHIVE_FILTER_NONE) {
archive_read_free(a);
close(bsdtar->fd);
lafe_errc(1, 0,
@@ -367,8 +403,7 @@ tar_mode_u(struct bsdtar *bsdtar)
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))
- lafe_errc(1, 0, "%s", archive_error_string(a));
+ set_writer_options(bsdtar, a);
if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd))
lafe_errc(1, 0, "%s", archive_error_string(a));
@@ -544,7 +579,7 @@ cleanup:
if (bsdtar->option_totals) {
fprintf(stderr, "Total bytes written: %s\n",
- tar_i64toa(archive_position_compressed(a)));
+ tar_i64toa(archive_filter_bytes(a, -1)));
}
archive_write_free(a);
@@ -612,7 +647,9 @@ append_archive_filename(struct bsdtar *bsdtar, struct archive *a,
ina = archive_read_new();
archive_read_support_format_all(ina);
archive_read_support_filter_all(ina);
- if (archive_read_open_file(ina, filename, bsdtar->bytes_per_block)) {
+ set_reader_options(bsdtar, a);
+ if (archive_read_open_filename(ina, filename,
+ bsdtar->bytes_per_block)) {
lafe_warnc(0, "%s", archive_error_string(ina));
bsdtar->return_value = 1;
return (0);
@@ -942,8 +979,8 @@ report_write(struct bsdtar *bsdtar, struct archive *a,
if (bsdtar->verbose)
fprintf(stderr, "\n");
- comp = archive_position_compressed(a);
- uncomp = archive_position_uncompressed(a);
+ comp = archive_filter_bytes(a, -1);
+ uncomp = archive_filter_bytes(a, 0);
fprintf(stderr, "In: %d files, %s bytes;",
archive_file_count(a), tar_i64toa(uncomp));
if (comp > uncomp)
@@ -971,10 +1008,6 @@ test_for_append(struct bsdtar *bsdtar)
if (bsdtar->filename == NULL)
lafe_errc(1, 0, "Cannot append to stdout.");
- if (bsdtar->create_compression != 0)
- lafe_errc(1, 0,
- "Cannot append to %s with compression", bsdtar->filename);
-
if (stat(bsdtar->filename, &s) != 0)
return;
OpenPOWER on IntegriCloud