]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tar: add new options to allow fine-tuning of --preserve-permissions
authorMartin Matuska <martin@matuska.org>
Thu, 23 Feb 2017 21:56:40 +0000 (22:56 +0100)
committerMartin Matuska <martin@matuska.org>
Fri, 24 Feb 2017 01:19:28 +0000 (02:19 +0100)
Allow enabling and disabling reading or writing of:
Access Control Lists (--acls, --no-acls)
Extended file flags (--fflags, --no-fflags)
Extended attributes (--xattrs, --no-xattrs)
Mac OS X metadata in AppleDouble (--mac-metadata, --no-mac-metadata)

Make --disable-copyfile an alias to --no-mac-metadata.

tar/bsdtar.1
tar/bsdtar.c
tar/bsdtar.h
tar/cmdline.c

index 9eadaaf885b1bd730b01d6b20c32ab2d5f2e6a20..c4486a3dccb2074ad7aaa12c6bd39046f189b2f3 100644 (file)
@@ -1,4 +1,5 @@
 .\" Copyright (c) 2003-2007 Tim Kientzle
+.\" Copyright (c) 2017 Martin Matuska
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -24,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 16, 2014
+.Dd February 23, 2017
 .Dt TAR 1
 .Os
 .Sh NAME
@@ -124,7 +125,7 @@ Unless specifically stated otherwise, options are applicable in
 all operating modes.
 .Bl -tag -width indent
 .It Cm @ Ns Pa archive
-(c and r mode only)
+(c and r modes only)
 The specified archive is opened and the entries
 in it will be appended to the current archive.
 As a simple example,
@@ -164,6 +165,13 @@ 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 Fl acls
+(c, r, u, x modes only)
+Archive or extract ACLs. This is the reverse of
+.Fl Fl no-acls
+and the default behavior in c, r, and u modes or if
+.Nm
+is run in x mode as root.
 .It Fl B , Fl Fl read-full-blocks
 Ignored for compatibility with other
 .Xr tar 1
@@ -188,15 +196,18 @@ options and before extracting any files.
 (x mode only)
 Before removing file system objects to replace them, clear platform-specific
 file flags that might prevent removal.
-.It Fl Fl disable-copyfile
-Mac OS X specific.
-Disable the use of
-.Xr copyfile 3 .
 .It Fl Fl exclude Ar pattern
 Do not process files or directories that match the
 specified pattern.
 Note that exclusions take precedence over patterns or filenames
 specified on the command line.
+.It Fl Fl fflags
+(c, r, u, x modes only)
+Archive or extract file flags. This is the reverse of
+.Fl Fl no-fflags
+and the default behavior in c, r, and u modes or if
+.Nm
+is run in x mode as root.
 .It Fl Fl format Ar format
 (c, r, u mode only)
 Use the specified format for the created archive.
@@ -245,11 +256,11 @@ On create, this sets the group name that will be stored
 in the archive;
 the name will not be verified against the system group database.
 .It Fl H
-(c and r mode only)
+(c and r modes only)
 Symbolic links named on the command line will be followed; the
 target of the link will be archived, not the link itself.
 .It Fl h
-(c and r mode only)
+(c and r modes only)
 Synonym for
 .Fl L .
 .It Fl I
@@ -259,7 +270,8 @@ Synonym for
 Show usage.
 .It Fl Fl hfsCompression
 (x mode only)
-Mac OS X specific(v10.6 or later). Compress extracted regular files with HFS+ compression.
+Mac OS X specific (v10.6 or later). Compress extracted regular files with HFS+
+compression.
 .It Fl Fl ignore-zeros
 An alias of
 .Fl Fl options Cm read_concatenated_archives
@@ -310,7 +322,7 @@ later copies will not overwrite earlier copies.
 Do not overwrite existing files that are newer than the
 versions appearing in the archive being extracted.
 .It Fl L , Fl Fl dereference
-(c and r mode only)
+(c and r modes only)
 All symbolic links will be followed.
 Normally, symbolic links are archived as such.
 With this option, the target of the link will be archived instead.
@@ -345,6 +357,15 @@ In extract or list modes, this option is ignored.
 (x mode only)
 Do not extract modification time.
 By default, the modification time is set to the time stored in the archive.
+.It Fl Fl mac-metadata
+(c, r, u and x mode only)
+Mac OS X specific. Archive or extract ACLs and extended attributes using
+.Xr copyfile 3
+in AppleDouble format. This is the reverse of
+.Fl Fl no-mac-metadata .
+and the default behavior in c, r, and u modes or if
+.Nm
+is run in x mode as root.
 .It Fl n , Fl Fl norecurse , Fl Fl no-recursion
 (c, r, u modes only)
 Do not recursively archive the contents of directories.
@@ -385,6 +406,30 @@ This is often used to read filenames output by the
 .Fl print0
 option to
 .Xr find 1 .
+.It Fl Fl no-acls
+(c, r, u, x modes only)
+Do not archive or extract ACLs. This is the reverse of
+.Fl Fl acls
+and the default behavior if
+.Nm
+is run as non-root in x mode.
+.It Fl Fl no-fflags
+(c, r, u, x modes only)
+Do not archive or extract file flags. This is the reverse of
+.Fl Fl fflags
+and the default behavior if
+.Nm
+is run as non-root in x mode.
+.It Fl Fl no-mac-metadata
+(x mode only)
+Mac OS X specific. Do not archive or extract ACLs and extended attributes using
+.Xr copyfile 3
+in AppleDouble format. This is the reverse of
+.Fl Fl mac-metadata .
+and the default behavior if
+.Nm
+is run as non-root in x mode.
+.It Fl n , Fl Fl norecurse , Fl Fl no-recursion
 .It Fl Fl no-same-owner
 (x mode only)
 Do not extract owner and group IDs.
@@ -401,7 +446,21 @@ This is the reverse of
 .Fl p
 and the default behavior if
 .Nm
-is run as non-root.
+is run as non-root and can be overridden by also specifying
+.Fl Fl acls ,
+.Fl Fl fflags ,
+.Fl Fl mac-metadata,
+.Fl Fl same-owner ,
+.Fl Fl same-permissions
+and
+.Fl Fl xattrs .
+.It Fl Fl no-xattrs
+(c, r, u, x modes only)
+Do not archive or extract extended attributes. This is the reverse of
+.Fl Fl xattrs
+and the default behavior if
+.Nm
+is run as non-root in x mode.
 .It Fl Fl numeric-owner
 This is equivalent to
 .Fl Fl uname
@@ -583,14 +642,18 @@ This option suppresses these behaviors.
 .It Fl p , Fl Fl insecure , Fl Fl preserve-permissions
 (x mode only)
 Preserve file permissions.
-Attempt to restore the full permissions, including owner, file modes, file
-flags and ACLs, if available, for each item extracted from the archive.
-This is the default, if
+Attempt to restore the full permissions, including owner, file modes, ACLs,
+extended atributes and extended file flags, if available, for each item
+extracted from the archive. This is the default, if
 .Nm
 is being run by root and can be overridden by also specifying
-.Fl Fl no-same-owner
+.Fl Fl no-acls ,
+.Fl Fl no-fflags ,
+.Fl Fl no-mac-metadata,
+.Fl Fl no-same-owner ,
+.Fl Fl no-same-permissions
 and
-.Fl Fl no-same-permissions .
+.Fl Fl no-xattrs .
 .It Fl Fl passphrase Ar passphrase
 The
 .Pa passphrase
@@ -692,7 +755,7 @@ you probably want to use
 .Fl n
 as well.
 .It Fl Fl totals
-(c, r, u mode only)
+(c, r, u modes only)
 After archiving all files, print a summary to stderr.
 .It Fl U , Fl Fl unlink , Fl Fl unlink-first
 (x mode only)
@@ -754,6 +817,13 @@ Read a list of exclusion patterns from the specified file.
 See
 .Fl Fl exclude
 for more information about the handling of exclusions.
+.It Fl Fl xattrs
+(c, r, u, x modes only)
+Archive or extract extended attributes. This is the reverse of
+.Fl Fl no-xattrs
+and the default behavior in c, r, and u modes or if
+.Nm
+is run in x mode as root.
 .It Fl y
 (c mode only)
 Compress the resulting archive with
index 8c7ffe806768875de9eb7d77f710e576e16ba29b..591da1954c59f736c69e001f149a45ffe8138071 100644 (file)
@@ -253,6 +253,11 @@ main(int argc, char **argv)
                case 'a': /* GNU tar */
                        bsdtar->flags |= OPTFLAG_AUTO_COMPRESS;
                        break;
+               case OPTION_ACLS: /* GNU tar */
+                       bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL;
+                       bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_NO_ACL;
+                       bsdtar->flags |= OPTFLAG_ACLS;
+                       break;
                case 'B': /* GNU tar */
                        /* libarchive doesn't need this; just ignore it. */
                        break;
@@ -293,15 +298,17 @@ main(int argc, char **argv)
                        bsdtar->extract_flags |=
                            ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS;
                        break;
-               case OPTION_DISABLE_COPYFILE: /* Mac OS X */
-                       bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_MAC_COPYFILE;
-                       break;
                case OPTION_EXCLUDE: /* GNU tar */
                        if (archive_match_exclude_pattern(
                            bsdtar->matching, bsdtar->argument) != ARCHIVE_OK)
                                lafe_errc(1, 0,
                                    "Couldn't exclude %s\n", bsdtar->argument);
                        break;
+               case OPTION_FFLAGS:
+                       bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS;
+                       bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_NO_FFLAGS;
+                       bsdtar->flags |= OPTFLAG_FFLAGS;
+                       break;
                case OPTION_FORMAT: /* GNU tar, others */
                        cset_set_format(bsdtar->cset, bsdtar->argument);
                        break;
@@ -420,6 +427,11 @@ main(int argc, char **argv)
                case 'm': /* SUSv2 */
                        bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME;
                        break;
+               case OPTION_MAC_METADATA: /* Mac OS X */
+                       bsdtar->readdisk_flags |= ARCHIVE_READDISK_MAC_COPYFILE;
+                       bsdtar->extract_flags |= ARCHIVE_EXTRACT_MAC_METADATA;
+                       bsdtar->flags |= OPTFLAG_MAC_METADATA;
+                       break;
                case 'n': /* GNU tar */
                        bsdtar->flags |= OPTFLAG_NO_SUBDIRS;
                        break;
@@ -465,6 +477,21 @@ main(int argc, char **argv)
                        bsdtar->extract_flags |=
                            ARCHIVE_EXTRACT_NO_HFS_COMPRESSION;
                        break;
+               case OPTION_NO_ACLS: /* GNU tar */
+                       bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_ACL;
+                       bsdtar->readdisk_flags |= ARCHIVE_READDISK_NO_ACL;
+                       bsdtar->flags |= OPTFLAG_NO_ACLS;
+                       break;
+               case OPTION_NO_FFLAGS:
+                       bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_FFLAGS;
+                       bsdtar->readdisk_flags |= ARCHIVE_READDISK_NO_FFLAGS;
+                       bsdtar->flags |= OPTFLAG_NO_FFLAGS;
+                       break;
+               case OPTION_NO_MAC_METADATA: /* Mac OS X */
+                       bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_MAC_COPYFILE;
+                       bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_MAC_METADATA;
+                       bsdtar->flags |= OPTFLAG_NO_MAC_METADATA;
+                       break;
                case OPTION_NO_SAME_OWNER: /* GNU tar */
                        bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER;
                        break;
@@ -475,10 +502,10 @@ main(int argc, char **argv)
                        bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_FFLAGS;
                        bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_MAC_METADATA;
                        break;
-               case OPTION_NO_XATTR: /* Issue #131 */
+               case OPTION_NO_XATTRS: /* GNU tar */
                        bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_XATTR;
                        bsdtar->readdisk_flags |= ARCHIVE_READDISK_NO_XATTR;
-                       bsdtar->flags |= OPTFLAG_NO_XATTR;
+                       bsdtar->flags |= OPTFLAG_NO_XATTRS;
                        break;
                case OPTION_NULL: /* GNU tar */
                        bsdtar->flags |= OPTFLAG_NULL;
@@ -655,6 +682,11 @@ main(int argc, char **argv)
                case 'x': /* SUSv2 */
                        set_mode(bsdtar, opt);
                        break;
+               case OPTION_XATTRS: /* GNU tar */
+                       bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR;
+                       bsdtar->readdisk_flags &= ~ARCHIVE_READDISK_NO_XATTR;
+                       bsdtar->flags |= OPTFLAG_XATTRS;
+                       break;
                case 'y': /* FreeBSD version of GNU tar */
                        if (compression != '\0')
                                lafe_errc(1, 0,
@@ -715,8 +747,22 @@ main(int argc, char **argv)
                only_mode(bsdtar, "--nopreserveHFSCompression", "x");
        if (bsdtar->readdisk_flags & ARCHIVE_READDISK_HONOR_NODUMP)
                only_mode(bsdtar, "--nodump", "cru");
-       if (bsdtar->flags & OPTFLAG_NO_XATTR)
-               only_mode(bsdtar, "--no-xattr", "crux");
+       if (bsdtar->flags & OPTFLAG_ACLS)
+               only_mode(bsdtar, "--acls", "crux");
+       if (bsdtar->flags & OPTFLAG_NO_ACLS)
+               only_mode(bsdtar, "--no-acls", "crux");
+       if (bsdtar->flags & OPTFLAG_XATTRS)
+               only_mode(bsdtar, "--xattrs", "crux");
+       if (bsdtar->flags & OPTFLAG_NO_XATTRS)
+               only_mode(bsdtar, "--no-xattrs", "crux");
+       if (bsdtar->flags & OPTFLAG_FFLAGS)
+               only_mode(bsdtar, "--fflags", "crux");
+       if (bsdtar->flags & OPTFLAG_NO_FFLAGS)
+               only_mode(bsdtar, "--no-fflags", "crux");
+       if (bsdtar->flags & OPTFLAG_MAC_METADATA)
+               only_mode(bsdtar, "--mac-metadata", "crux");
+       if (bsdtar->flags & OPTFLAG_NO_MAC_METADATA)
+               only_mode(bsdtar, "--no-mac-metadata", "crux");
        if (bsdtar->flags & OPTFLAG_O) {
                switch (bsdtar->mode) {
                case 'c':
index 89cf2f9a966678460f18ad484e84c40292efbf3e..ee9c6485fccc8e038d6eddc8ec4da46f1cd34b5f 100644 (file)
@@ -50,7 +50,7 @@ struct bsdtar {
        int               bytes_per_block; /* -b block_size */
        int               bytes_in_last_block; /* See -b handling. */
        int               verbose;   /* -v */
-       int               flags; /* Bitfield of boolean options */
+       unsigned int      flags; /* Bitfield of boolean options */
        int               extract_flags; /* Flags for extract operation */
        int               readdisk_flags; /* Flags for read disk operation */
        int               strip_components; /* Remove this many leading dirs */
@@ -118,16 +118,24 @@ struct bsdtar {
 #define        OPTFLAG_TOTALS          (0x00001000)    /* --totals */
 #define        OPTFLAG_UNLINK_FIRST    (0x00002000)    /* -U */
 #define        OPTFLAG_WARN_LINKS      (0x00004000)    /* --check-links */
-#define        OPTFLAG_NO_XATTR        (0x00008000)    /* --no-xattr */
+#define        OPTFLAG_NO_XATTRS       (0x00008000)    /* --no-xattrs */
+#define        OPTFLAG_XATTRS          (0x00010000)    /* --xattrs */
+#define        OPTFLAG_NO_ACLS         (0x00020000)    /* --no-acls */
+#define        OPTFLAG_ACLS            (0x00040000)    /* --acls */
+#define        OPTFLAG_NO_FFLAGS       (0x00080000)    /* --no-fflags */
+#define        OPTFLAG_FFLAGS          (0x00100000)    /* --fflags */
+#define        OPTFLAG_NO_MAC_METADATA (0x00200000)    /* --no-mac-metadata */
+#define        OPTFLAG_MAC_METADATA    (0x00400000)    /* --mac-metadata */
 
 /* Fake short equivalents for long options that otherwise lack them. */
 enum {
-       OPTION_B64ENCODE = 1,
+       OPTION_ACLS = 1,
+       OPTION_B64ENCODE,
        OPTION_CHECK_LINKS,
        OPTION_CHROOT,
        OPTION_CLEAR_NOCHANGE_FFLAGS,
-       OPTION_DISABLE_COPYFILE,
        OPTION_EXCLUDE,
+       OPTION_FFLAGS,
        OPTION_FORMAT,
        OPTION_GID,
        OPTION_GNAME,
@@ -142,15 +150,19 @@ enum {
        OPTION_LZIP,
        OPTION_LZMA,
        OPTION_LZOP,
+       OPTION_MAC_METADATA,
        OPTION_NEWER_CTIME,
        OPTION_NEWER_CTIME_THAN,
        OPTION_NEWER_MTIME,
        OPTION_NEWER_MTIME_THAN,
        OPTION_NODUMP,
        OPTION_NOPRESERVE_HFS_COMPRESSION,
+       OPTION_NO_ACLS,
+       OPTION_NO_FFLAGS,
+       OPTION_NO_MAC_METADATA,
        OPTION_NO_SAME_OWNER,
        OPTION_NO_SAME_PERMISSIONS,
-       OPTION_NO_XATTR,
+       OPTION_NO_XATTRS,
        OPTION_NULL,
        OPTION_NUMERIC_OWNER,
        OPTION_OLDER_CTIME,
@@ -168,7 +180,8 @@ enum {
        OPTION_UNAME,
        OPTION_USE_COMPRESS_PROGRAM,
        OPTION_UUENCODE,
-       OPTION_VERSION
+       OPTION_VERSION,
+       OPTION_XATTRS
 };
 
 int    bsdtar_getopt(struct bsdtar *);
index c87741cc565eca11dd1c2ec193a9e73a21c8c3f2..e36c545b3336ebe2657f5f30337552d68c7c781e 100644 (file)
@@ -65,6 +65,7 @@ static const struct bsdtar_option {
 } tar_longopts[] = {
        { "absolute-paths",       0, 'P' },
        { "append",               0, 'r' },
+       { "acls",                 0, OPTION_ACLS },
        { "auto-compress",        0, 'a' },
        { "b64encode",            0, OPTION_B64ENCODE },
        { "block-size",           1, 'b' },
@@ -81,11 +82,12 @@ static const struct bsdtar_option {
        { "create",               0, 'c' },
        { "dereference",          0, 'L' },
        { "directory",            1, 'C' },
-       { "disable-copyfile",     0, OPTION_DISABLE_COPYFILE },
+       { "disable-copyfile",     0, OPTION_NO_MAC_METADATA },
        { "exclude",              1, OPTION_EXCLUDE },
        { "exclude-from",         1, 'X' },
        { "extract",              0, 'x' },
        { "fast-read",            0, 'q' },
+       { "fflags",               0, OPTION_FFLAGS },
        { "file",                 1, 'f' },
        { "files-from",           1, 'T' },
        { "format",               1, OPTION_FORMAT },
@@ -108,6 +110,7 @@ static const struct bsdtar_option {
        { "lzip",                 0, OPTION_LZIP },
        { "lzma",                 0, OPTION_LZMA },
        { "lzop",                 0, OPTION_LZOP },
+       { "mac-metadata",         0, OPTION_MAC_METADATA },
        { "modification-time",    0, 'm' },
        { "newer",                1, OPTION_NEWER_CTIME },
        { "newer-ctime",          1, OPTION_NEWER_CTIME },
@@ -115,10 +118,14 @@ static const struct bsdtar_option {
        { "newer-mtime",          1, OPTION_NEWER_MTIME },
        { "newer-mtime-than",     1, OPTION_NEWER_MTIME_THAN },
        { "newer-than",           1, OPTION_NEWER_CTIME_THAN },
+       { "no-acls",              0, OPTION_NO_ACLS },
+       { "no-fflags",            0, OPTION_NO_FFLAGS },
+       { "no-mac-metadata",      0, OPTION_NO_MAC_METADATA },
        { "no-recursion",         0, 'n' },
        { "no-same-owner",        0, OPTION_NO_SAME_OWNER },
        { "no-same-permissions",  0, OPTION_NO_SAME_PERMISSIONS },
-       { "no-xattr",             0, OPTION_NO_XATTR },
+       { "no-xattr",             0, OPTION_NO_XATTRS },
+       { "no-xattrs",            0, OPTION_NO_XATTRS },
        { "nodump",               0, OPTION_NODUMP },
        { "nopreserveHFSCompression",0, OPTION_NOPRESERVE_HFS_COMPRESSION },
        { "norecurse",            0, 'n' },
@@ -151,6 +158,7 @@ static const struct bsdtar_option {
        { "uuencode",             0, OPTION_UUENCODE },
        { "verbose",              0, 'v' },
        { "version",              0, OPTION_VERSION },
+       { "xattrs",               0, OPTION_XATTRS },
        { "xz",                   0, 'J' },
        { NULL, 0, 0 }
 };