diff options
author | kientzle <kientzle@FreeBSD.org> | 2009-04-17 03:45:15 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2009-04-17 03:45:15 +0000 |
commit | 4e8cb50d8bef897f785cb884230eb42be06c0541 (patch) | |
tree | 0514fae58a31453b4032bc7b7cbcc20e4d70a8e9 | |
parent | f1f2531950c611a392373891086d6ef3a96ae71d (diff) | |
download | FreeBSD-src-4e8cb50d8bef897f785cb884230eb42be06c0541.zip FreeBSD-src-4e8cb50d8bef897f785cb884230eb42be06c0541.tar.gz |
Merge remaining changes from libarchive.googlecode.com:
* Add xz and lzma compression options
* Rename --format-options to simply --options
* Add --same-owner for GNU tar compat
* Add -lmd and -lcrypto to fix link
* Documentation
-rw-r--r-- | usr.bin/tar/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/tar/bsdtar.1 | 85 | ||||
-rw-r--r-- | usr.bin/tar/bsdtar.c | 47 | ||||
-rw-r--r-- | usr.bin/tar/bsdtar.h | 6 | ||||
-rw-r--r-- | usr.bin/tar/cmdline.c | 7 | ||||
-rw-r--r-- | usr.bin/tar/write.c | 43 |
6 files changed, 150 insertions, 42 deletions
diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile index 6febbd7..28007f7e 100644 --- a/usr.bin/tar/Makefile +++ b/usr.bin/tar/Makefile @@ -1,11 +1,11 @@ # $FreeBSD$ PROG= bsdtar -BSDTAR_VERSION_STRING=2.6.901a +BSDTAR_VERSION_STRING=2.7.0 SRCS= bsdtar.c cmdline.c getdate.c matching.c read.c siginfo.c subst.c tree.c util.c write.c WARNS?= 5 DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ} -LDADD= -larchive -lbz2 -lz +LDADD= -larchive -lbz2 -lz -lmd -lcrypto CFLAGS+= -DBSDTAR_VERSION_STRING=\"${BSDTAR_VERSION_STRING}\" CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\" CFLAGS+= -I${.CURDIR} diff --git a/usr.bin/tar/bsdtar.1 b/usr.bin/tar/bsdtar.1 index 5e2ffcd..8baab7a 100644 --- a/usr.bin/tar/bsdtar.1 +++ b/usr.bin/tar/bsdtar.1 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 15, 2008 +.Dd March 25, 2009 .Dt BSDTAR 1 .Os .Sh NAME @@ -37,12 +37,12 @@ .Nm .Brq Fl c .Op Ar options -.Op Ar files | directories +.Op Ar files | Ar directories .Nm .Brq Fl r | Fl u .Fl f Ar archive-file .Op Ar options -.Op Ar files | directories +.Op Ar files | Ar directories .Nm .Brq Fl t | Fl x .Op Ar options @@ -305,6 +305,64 @@ A synonym for .It Fl -one-file-system (c, r, and u modes) Do not cross mount points. +.It Fl -options Ar options +Select optional behaviors for particular modules. +The argument is a text string containing comma-separated +keywords and values. +These are passed to the modules that handle particular +formats to control how those formats will behave. +Each option has one of the following forms: +.Bl -tag -compact -width indent +.It Ar key=value +The key will be set to the specified value in every module that supports it. +Modules that do not support this key will ignore it. +.It Ar key +The key will be enabled in every module that supports it. +This is equivalent to +.Ar key Ns Cm =1 . +.It Ar !key +The key will be disabled in every module that supports it. +.It Ar module:key=value , Ar module:key , Ar module:!key +As above, but the corresponding key and value will be provided +only to modules whose name matches +.Ar module . +.El +The currently supported modules and keys are: +.Bl -tag -compact -width indent +.It Cm iso9660:joliet +Support Joliet extensions. +This is enabled by default, use +.Cm !joliet +or +.Cm iso9660:!joliet +to disable. +.It Cm gzip:compression-level +A decimal integer from 0 to 9 specifying the gzip 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 +The mtree writer module allows you to specify which mtree keywords +will be included in the output. +Supported keywords include: +.Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , +.Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , +.Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname . +The default is equivalent to: +.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . +.It Cm mtree:all +Enables all of the above keywords. +You can also use +.Cm mtree:!all +to disable all keywords. +.It Cm mtree:use-set +Enable generation of +.Cm /set +lines in the output. +.It Cm mtree:indent +XXX need explanation XXX +.El +If a provided option is not supported by any module, that +is a fatal error. .It Fl P Preserve pathnames. By default, absolute pathnames (those that begin with a / @@ -555,6 +613,27 @@ switches accept a variety of common date and time specifications, including .Dq 5 minutes ago , and .Dq 19:14 PST May 1 . +.Pp +The +.Fl -options +argument can be used to control various details of archive generation +or reading. +For example, you can generate mtree output which only contains +.Cm type , Cm time , +and +.Cm uid +keywords: +.Dl Nm Fl cf Pa file.tar Fl -format=mtree Fl -options='!all,type,time,uid' Pa dir +or you can set the compression level used by gzip or xz compression: +.Dl Nm Fl czf Pa file.tar Fl -options='compression-level=9' . +For more details, see the explanation of the +.Fn archive_read_set_options +and +.Fn archive_write_set_options +API calls that are described in +.Xr archive_read 3 +and +.Xr archive_write 3 . .Sh COMPATIBILITY The bundled-arguments format is supported for compatibility with historic implementations. diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index e90afbc..cd6fa63 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -73,7 +73,7 @@ __FBSDID("$FreeBSD$"); #ifdef __linux #define _PATH_DEFTAPE "/dev/st0" #endif -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN__) #define _PATH_DEFTAPE "\\\\.\\tape0" #endif @@ -113,8 +113,10 @@ main(int argc, char **argv) memset(bsdtar, 0, sizeof(*bsdtar)); bsdtar->fd = -1; /* Mark as "unused" */ option_o = 0; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN__) /* Make sure open() function will be used with a binary mode. */ + /* on cygwin, we need something similar, but instead link against */ + /* a special startup object, binmode.o */ _set_fmode(_O_BINARY); #endif @@ -122,7 +124,7 @@ main(int argc, char **argv) if (*argv == NULL) bsdtar->progname = "bsdtar"; else { -#if _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN__) bsdtar->progname = strrchr(*argv, '\\'); #else bsdtar->progname = strrchr(*argv, '/'); @@ -166,10 +168,6 @@ main(int argc, char **argv) bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR; bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; } -#ifdef _WIN32 - /* Windows cannot set UNIX like uid/gid. */ - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; -#endif bsdtar->argv = argv; bsdtar->argc = argc; @@ -212,8 +210,8 @@ main(int argc, char **argv) case OPTION_FORMAT: /* GNU tar, others */ bsdtar->create_format = bsdtar->optarg; break; - case OPTION_FORMAT_OPTIONS: - bsdtar->option_format_options = bsdtar->optarg; + case OPTION_OPTIONS: + bsdtar->option_options = bsdtar->optarg; break; case 'f': /* SUSv2 */ bsdtar->filename = bsdtar->optarg; @@ -269,6 +267,19 @@ main(int argc, char **argv) usage(bsdtar); #endif break; + case 'J': /* GNU tar 1.21 and later */ +#if HAVE_LIBLZMA + if (bsdtar->create_compression != '\0') + bsdtar_errc(bsdtar, 1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; +#else + bsdtar_warnc(bsdtar, 0, + "xz compression not supported by this version of bsdtar"); + usage(bsdtar); +#endif + break; case 'k': /* GNU tar */ bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE; break; @@ -282,6 +293,19 @@ main(int argc, char **argv) /* GNU tar 1.13 used -l for --one-file-system */ bsdtar->option_warn_links = 1; break; + case OPTION_LZMA: +#if HAVE_LIBLZMA + if (bsdtar->create_compression != '\0') + bsdtar_errc(bsdtar, 1, 0, + "Can't specify both -%c and -%c", opt, + bsdtar->create_compression); + bsdtar->create_compression = opt; +#else + bsdtar_warnc(bsdtar, 0, + "lzma compression not supported by this version of bsdtar"); + usage(bsdtar); +#endif + break; case 'm': /* SUSv2 */ bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME; break; @@ -392,6 +416,9 @@ main(int argc, char **argv) usage(bsdtar); #endif break; + case OPTION_SAME_OWNER: /* GNU tar */ + bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER; + break; case OPTION_STRIP_COMPONENTS: /* GNU tar 1.15 */ bsdtar->strip_components = atoi(bsdtar->optarg); break; @@ -632,7 +659,7 @@ static const char *long_help_msg = " -w Interactive\n" "Create: %p -c [options] [<file> | <dir> | @<archive> | -C <dir> ]\n" " <file>, <dir> add these items to archive\n" - " -z, -j Compress archive with gzip/bzip2\n" + " -z, -j, -J, --lzma Compress archive with gzip/bzip2/xz/lzma\n" " --format {ustar|pax|cpio|shar} Select archive format\n" " --exclude <pattern> Skip files that match pattern\n" " -C <dir> Change to <dir> before processing remaining files\n" diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h index 1e6673a..f0f3e54 100644 --- a/usr.bin/tar/bsdtar.h +++ b/usr.bin/tar/bsdtar.h @@ -60,7 +60,7 @@ struct bsdtar { char option_chroot; /* --chroot */ char option_dont_traverse_mounts; /* --one-file-system */ char option_fast_read; /* --fast-read */ - const char *option_format_options; /* --format-options */ + const char *option_options; /* --options */ char option_honor_nodump; /* --nodump */ char option_interactive; /* -w */ char option_no_owner; /* -o */ @@ -111,10 +111,11 @@ enum { OPTION_CHROOT, OPTION_EXCLUDE, OPTION_FORMAT, - OPTION_FORMAT_OPTIONS, + OPTION_OPTIONS, OPTION_HELP, OPTION_INCLUDE, OPTION_KEEP_NEWER_FILES, + OPTION_LZMA, OPTION_NEWER_CTIME, OPTION_NEWER_CTIME_THAN, OPTION_NEWER_MTIME, @@ -126,6 +127,7 @@ enum { OPTION_NUMERIC_OWNER, OPTION_ONE_FILE_SYSTEM, OPTION_POSIX, + OPTION_SAME_OWNER, OPTION_STRIP_COMPONENTS, OPTION_TOTALS, OPTION_USE_COMPRESS_PROGRAM, diff --git a/usr.bin/tar/cmdline.c b/usr.bin/tar/cmdline.c index ad8b487..efaeafd 100644 --- a/usr.bin/tar/cmdline.c +++ b/usr.bin/tar/cmdline.c @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$"); * Short options for tar. Please keep this sorted. */ static const char *short_options - = "Bb:C:cf:HhI:jkLlmnOoPpqrSs:T:tUuvW:wX:xyZz"; + = "Bb:C:cf:HhI:JjkLlmnOoPpqrSs:T:tUuvW:wX:xyZz"; /* * Long options for tar. Please keep this list sorted. @@ -83,7 +83,7 @@ static struct option { { "file", 1, 'f' }, { "files-from", 1, 'T' }, { "format", 1, OPTION_FORMAT }, - { "format-options", 1, OPTION_FORMAT_OPTIONS }, + { "options", 1, OPTION_OPTIONS }, { "gunzip", 0, 'z' }, { "gzip", 0, 'z' }, { "help", 0, OPTION_HELP }, @@ -93,6 +93,7 @@ static struct option { { "keep-newer-files", 0, OPTION_KEEP_NEWER_FILES }, { "keep-old-files", 0, 'k' }, { "list", 0, 't' }, + { "lzma", 0, OPTION_LZMA }, { "modification-time", 0, 'm' }, { "newer", 1, OPTION_NEWER_CTIME }, { "newer-ctime", 1, OPTION_NEWER_CTIME }, @@ -111,6 +112,7 @@ static struct option { { "posix", 0, OPTION_POSIX }, { "preserve-permissions", 0, 'p' }, { "read-full-blocks", 0, 'B' }, + { "same-owner", 0, OPTION_SAME_OWNER }, { "same-permissions", 0, 'p' }, { "strip-components", 1, OPTION_STRIP_COMPONENTS }, { "to-stdout", 0, 'O' }, @@ -122,6 +124,7 @@ static struct option { { "use-compress-program", 1, OPTION_USE_COMPRESS_PROGRAM }, { "verbose", 0, 'v' }, { "version", 0, OPTION_VERSION }, + { "xz", 0, 'J' }, { NULL, 0, 0 } }; diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 6f89286..efc94de 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -189,6 +189,14 @@ tar_mode_c(struct bsdtar *bsdtar) archive_write_set_compression_bzip2(a); break; #endif +#ifdef HAVE_LIBLZMA + case 'J': + archive_write_set_compression_xz(a); + break; + case OPTION_LZMA: + archive_write_set_compression_lzma(a); + break; +#endif #ifdef HAVE_LIBZ case 'z': archive_write_set_compression_gzip(a); @@ -204,16 +212,10 @@ tar_mode_c(struct bsdtar *bsdtar) } } - r = archive_write_open_file(a, bsdtar->filename); - if (r != ARCHIVE_OK) + if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) + bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); + if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename)) bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); - - if (bsdtar->option_format_options != NULL) { - r = archive_write_set_options(a, bsdtar->option_format_options); - if (r != ARCHIVE_OK) - bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); - } - write_archive(a, bsdtar); } @@ -299,12 +301,10 @@ tar_mode_r(struct bsdtar *bsdtar) archive_write_set_format(a, format); } lseek(bsdtar->fd, end_offset, SEEK_SET); /* XXX check return val XXX */ - archive_write_open_fd(a, bsdtar->fd); /* XXX check return val XXX */ - if (bsdtar->option_format_options != NULL) { - r = archive_write_set_options(a, bsdtar->option_format_options); - if (r != ARCHIVE_OK) - bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); - } + if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) + bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); + if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) + bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); write_archive(a, bsdtar); /* XXX check return val XXX */ @@ -321,7 +321,6 @@ tar_mode_u(struct bsdtar *bsdtar) int format; struct archive_dir_entry *p; struct archive_dir archive_dir; - int r; bsdtar->archive_dir = &archive_dir; memset(&archive_dir, 0, sizeof(archive_dir)); @@ -385,12 +384,10 @@ tar_mode_u(struct bsdtar *bsdtar) archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK); lseek(bsdtar->fd, end_offset, SEEK_SET); ftruncate(bsdtar->fd, end_offset); - archive_write_open_fd(a, bsdtar->fd); - if (bsdtar->option_format_options != NULL) { - r = archive_write_set_options(a, bsdtar->option_format_options); - if (r != ARCHIVE_OK) - bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); - } + if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) + bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); + if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) + bsdtar_errc(bsdtar, 1, 0, archive_error_string(a)); write_archive(a, bsdtar); @@ -457,7 +454,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) arg + 1) != 0) break; } else -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN__) write_hierarchy_win(bsdtar, a, arg, write_hierarchy); #else |