]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue #131: Implement tar --no-xattr
authorTim Kientzle <kientzle@acm.org>
Sat, 10 Jan 2015 19:55:29 +0000 (11:55 -0800)
committerTim Kientzle <kientzle@acm.org>
Sat, 10 Jan 2015 19:55:29 +0000 (11:55 -0800)
This option suppresses both archiving and
restoring xattrs.  The latter relies on existing
machinery; for the former, I've added a
ARCHIVE_READDISK_NO_XATTR flag to archive_read_disk.

Caveat: I've not implemented any tests for these new features.

libarchive/archive.h
libarchive/archive_read_disk_entry_from_file.c
libarchive/archive_read_disk_posix.c
libarchive/archive_read_disk_private.h
tar/bsdtar.c
tar/bsdtar.h
tar/cmdline.c

index 81ed63a13f6746cbd2674a08ef1a286ac9599a98..1f0fc3874313a12208f3a5d743d400bc959b5f26 100644 (file)
@@ -958,6 +958,8 @@ __LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
 #define        ARCHIVE_READDISK_MAC_COPYFILE           (0x0004)
 /* Default: Do not traverse mount points. */
 #define        ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS     (0x0008)
+/* Default: Xattrs are read from disk. */
+#define        ARCHIVE_READDISK_NO_XATTR               (0x0010)
 
 __LA_DECL int  archive_read_disk_set_behavior(struct archive *,
                    int flags);
index e81cbeccd163f0209daad153f74af44a9e5d9d8d..38303aa8725b900de952e8b4a5a86e43fc61a1ff 100644 (file)
@@ -251,9 +251,11 @@ archive_read_disk_entry_from_file(struct archive *_a,
 #endif /* HAVE_READLINK || HAVE_READLINKAT */
 
        r = setup_acls(a, entry, &fd);
-       r1 = setup_xattrs(a, entry, &fd);
-       if (r1 < r)
-               r = r1;
+       if (!a->suppress_xattr) {
+               r1 = setup_xattrs(a, entry, &fd);
+               if (r1 < r)
+                       r = r1;
+       }
        if (a->enable_copyfile) {
                r1 = setup_mac_metadata(a, entry, &fd);
                if (r1 < r)
index 71e63ac62864383fabf93f10989e85dbe106fe67..7a5a159f67c5ac94c91906de7171f31b42b6bf96 100644 (file)
@@ -609,6 +609,10 @@ archive_read_disk_set_behavior(struct archive *_a, int flags)
                a->traverse_mount_points = 0;
        else
                a->traverse_mount_points = 1;
+       if (flags & ARCHIVE_READDISK_NO_XATTR)
+               a->suppress_xattr = 1;
+       else
+               a->suppress_xattr = 0;
        return (r);
 }
 
index e5af16b9161ba10319865d46ced901fc47d294ed..de0142eddbb8b982b3cbfdac6f504b419529ee34 100644 (file)
@@ -68,6 +68,8 @@ struct archive_read_disk {
        int              enable_copyfile;
        /* Set 1 if users request to traverse mount points. */
        int              traverse_mount_points;
+       /* Set 1 if users want to suppress xattr information. */
+       int              suppress_xattr;
 
        const char * (*lookup_gname)(void *private, int64_t gid);
        void    (*cleanup_gname)(void *private);
index 4b4a5824b900703a7060369d98439d7a142387ea..a8c846b0c2405f356573937f75f7a303475e06ee 100644 (file)
@@ -472,6 +472,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 */
+                       bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_XATTR;
+                       bsdtar->readdisk_flags |= ARCHIVE_READDISK_NO_XATTR;
+                       break;
                case OPTION_NULL: /* GNU tar */
                        bsdtar->option_null++;
                        break;
@@ -707,6 +711,8 @@ 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->readdisk_flags & ARCHIVE_READDISK_NO_XATTR)
+               only_mode(bsdtar, "--no-xattr", "crux");
        if (option_o > 0) {
                switch (bsdtar->mode) {
                case 'c':
index 4050a81a7117a8fffab131c3a189e35d31e206a6..8e64b0a7986bd9110fc1750521dd76c4bd48dc02 100644 (file)
@@ -143,6 +143,7 @@ enum {
        OPTION_NOPRESERVE_HFS_COMPRESSION,
        OPTION_NO_SAME_OWNER,
        OPTION_NO_SAME_PERMISSIONS,
+       OPTION_NO_XATTR,
        OPTION_NULL,
        OPTION_NUMERIC_OWNER,
        OPTION_OLDER_CTIME,
index 974b6af89fc117247f171812d8f9583513673c95..bb905812d52bfd3fb1e640336354636461463b21 100644 (file)
@@ -116,6 +116,7 @@ static const struct bsdtar_option {
        { "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 },
        { "nodump",               0, OPTION_NODUMP },
        { "nopreserveHFSCompression",0, OPTION_NOPRESERVE_HFS_COMPRESSION },
        { "norecurse",            0, 'n' },