]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use ARCHIVE_READDISK_* flags as a internal bitfield, too
authorMartin Matuska <martin@matuska.org>
Wed, 22 Feb 2017 21:42:56 +0000 (22:42 +0100)
committerMartin Matuska <martin@matuska.org>
Wed, 22 Feb 2017 22:28:29 +0000 (23:28 +0100)
libarchive/archive_read_disk_entry_from_file.c
libarchive/archive_read_disk_posix.c
libarchive/archive_read_disk_private.h
libarchive/archive_read_disk_windows.c
libarchive/test/test_read_disk_directory_traversals.c

index fc9481d1a0879f0eb4c9f950b598cd3adeb328b5..1e20bea8414ee73dd4dbbe6c58736ab319ae14da 100644 (file)
@@ -270,14 +270,14 @@ archive_read_disk_entry_from_file(struct archive *_a,
 #endif /* HAVE_READLINK || HAVE_READLINKAT */
 
        r = 0;
-       if (!a->suppress_acl)
+       if ((a->flags & ARCHIVE_READDISK_NO_ACL) == 0)
                r = setup_acls(a, entry, &fd);
-       if (!a->suppress_xattr) {
+       if ((a->flags & ARCHIVE_READDISK_NO_XATTR) == 0) {
                r1 = setup_xattrs(a, entry, &fd);
                if (r1 < r)
                        r = r1;
        }
-       if (a->enable_copyfile) {
+       if (a->flags & ARCHIVE_READDISK_MAC_COPYFILE) {
                r1 = setup_mac_metadata(a, entry, &fd);
                if (r1 < r)
                        r = r1;
index 102f2a0a6af1b2e89f1d0519c2539611966281d1..d93d200aa3d1f2633c17b382385bfb078de6f2d4 100644 (file)
@@ -465,8 +465,7 @@ archive_read_disk_new(void)
        a->entry = archive_entry_new2(&a->archive);
        a->lookup_uname = trivial_lookup_uname;
        a->lookup_gname = trivial_lookup_gname;
-       a->enable_copyfile = 1;
-       a->traverse_mount_points = 1;
+       a->flags = ARCHIVE_READDISK_MAC_COPYFILE;
        a->open_on_current_dir = open_on_current_dir;
        a->tree_current_dir_fd = tree_current_dir_fd;
        a->tree_enter_working_dir = tree_enter_working_dir;
@@ -563,25 +562,19 @@ archive_read_disk_set_symlink_hybrid(struct archive *_a)
 int
 archive_read_disk_set_atime_restored(struct archive *_a)
 {
-#ifndef HAVE_UTIMES
-       static int warning_done = 0;
-#endif
        struct archive_read_disk *a = (struct archive_read_disk *)_a;
        archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
            ARCHIVE_STATE_ANY, "archive_read_disk_restore_atime");
 #ifdef HAVE_UTIMES
-       a->restore_time = 1;
+       a->flags |= ARCHIVE_READDISK_RESTORE_ATIME;
        if (a->tree != NULL)
                a->tree->flags |= needsRestoreTimes;
        return (ARCHIVE_OK);
 #else
-       if (warning_done)
-               /* Warning was already emitted; suppress further warnings. */
-               return (ARCHIVE_OK);
-
+       /* Display warning and unset flag */
        archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
            "Cannot restore access time on this system");
-       warning_done = 1;
+       a->flags &= ~ARCHIVE_READDISK_RESTORE_ATIME;
        return (ARCHIVE_WARN);
 #endif
 }
@@ -595,33 +588,14 @@ archive_read_disk_set_behavior(struct archive *_a, int flags)
        archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
            ARCHIVE_STATE_ANY, "archive_read_disk_honor_nodump");
 
+       a->flags = flags;
+
        if (flags & ARCHIVE_READDISK_RESTORE_ATIME)
                r = archive_read_disk_set_atime_restored(_a);
        else {
-               a->restore_time = 0;
                if (a->tree != NULL)
                        a->tree->flags &= ~needsRestoreTimes;
        }
-       if (flags & ARCHIVE_READDISK_HONOR_NODUMP)
-               a->honor_nodump = 1;
-       else
-               a->honor_nodump = 0;
-       if (flags & ARCHIVE_READDISK_MAC_COPYFILE)
-               a->enable_copyfile = 1;
-       else
-               a->enable_copyfile = 0;
-       if (flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS)
-               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;
-       if (flags & ARCHIVE_READDISK_NO_ACL)
-               a->suppress_acl = 1;
-       else
-               a->suppress_acl = 0;
        return (r);
 }
 
@@ -993,7 +967,7 @@ next_entry(struct archive_read_disk *a, struct tree *t,
        }
        if (t->initial_filesystem_id == -1)
                t->initial_filesystem_id = t->current_filesystem_id;
-       if (!a->traverse_mount_points) {
+       if (a->flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS) {
                if (t->initial_filesystem_id != t->current_filesystem_id)
                        descend = 0;
        }
@@ -1003,7 +977,7 @@ next_entry(struct archive_read_disk *a, struct tree *t,
         * Honor nodump flag.
         * If the file is marked with nodump flag, do not return this entry.
         */
-       if (a->honor_nodump) {
+       if (a->flags & ARCHIVE_READDISK_HONOR_NODUMP) {
 #if defined(HAVE_STRUCT_STAT_ST_FLAGS) && defined(UF_NODUMP)
                if (st->st_flags & UF_NODUMP)
                        return (ARCHIVE_RETRY);
@@ -1344,10 +1318,11 @@ _archive_read_disk_open(struct archive *_a, const char *pathname)
        struct archive_read_disk *a = (struct archive_read_disk *)_a;
 
        if (a->tree != NULL)
-               a->tree = tree_reopen(a->tree, pathname, a->restore_time);
+               a->tree = tree_reopen(a->tree, pathname,
+                   a->flags & ARCHIVE_READDISK_RESTORE_ATIME);
        else
                a->tree = tree_open(pathname, a->symlink_mode,
-                   a->restore_time);
+                   a->flags & ARCHIVE_READDISK_RESTORE_ATIME);
        if (a->tree == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate tar data");
@@ -2136,7 +2111,7 @@ tree_open(const char *path, int symlink_mode, int restore_time)
 static struct tree *
 tree_reopen(struct tree *t, const char *path, int restore_time)
 {
-       t->flags = (restore_time)?needsRestoreTimes:0;
+       t->flags = (restore_time != 0)?needsRestoreTimes:0;
        t->flags |= onInitialDir;
        t->visit_type = 0;
        t->tree_errno = 0;
index 54353da4a13d600436adce73a2fa5ad34def00cb..b5a8328b7bfe450b714a3c3e2f848b004c984e42 100644 (file)
@@ -63,18 +63,8 @@ struct archive_read_disk {
        int     (*tree_current_dir_fd)(struct tree*);
        int     (*tree_enter_working_dir)(struct tree*);
 
-       /* Set 1 if users request to restore atime . */
-       int              restore_time;
-       /* Set 1 if users request to honor nodump flag . */
-       int              honor_nodump;
-       /* Set 1 if users request to enable mac copyfile. */
-       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;
-       /* Set 1 if users want to suppress ACL information. */
-       int              suppress_acl;
+       /* Bitfield with ARCHIVE_READDISK_* tunables */
+       int     flags;
 
        const char * (*lookup_gname)(void *private, int64_t gid);
        void    (*cleanup_gname)(void *private);
index 27b75e3b10cecc85ebffe2239ead603fc76e4e6c..3b903304f08b750a838c9204ad68b1873730db71 100644 (file)
@@ -398,8 +398,7 @@ archive_read_disk_new(void)
        a->entry = archive_entry_new2(&a->archive);
        a->lookup_uname = trivial_lookup_uname;
        a->lookup_gname = trivial_lookup_gname;
-       a->enable_copyfile = 1;
-       a->traverse_mount_points = 1;
+       a->flags = ARCHIVE_READDISK_MAC_COPYFILE;
        return (&a->archive);
 }
 
@@ -495,7 +494,7 @@ archive_read_disk_set_atime_restored(struct archive *_a)
        struct archive_read_disk *a = (struct archive_read_disk *)_a;
        archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
            ARCHIVE_STATE_ANY, "archive_read_disk_restore_atime");
-       a->restore_time = 1;
+       a->flags |= ARCHIVE_READDISK_RESTORE_ATIME;
        if (a->tree != NULL)
                a->tree->flags |= needsRestoreTimes;
        return (ARCHIVE_OK);
@@ -510,25 +509,14 @@ archive_read_disk_set_behavior(struct archive *_a, int flags)
        archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
            ARCHIVE_STATE_ANY, "archive_read_disk_honor_nodump");
 
+       a->flags = flags;
+
        if (flags & ARCHIVE_READDISK_RESTORE_ATIME)
                r = archive_read_disk_set_atime_restored(_a);
        else {
-               a->restore_time = 0;
                if (a->tree != NULL)
                        a->tree->flags &= ~needsRestoreTimes;
        }
-       if (flags & ARCHIVE_READDISK_HONOR_NODUMP)
-               a->honor_nodump = 1;
-       else
-               a->honor_nodump = 0;
-       if (flags & ARCHIVE_READDISK_MAC_COPYFILE)
-               a->enable_copyfile = 1;
-       else
-               a->enable_copyfile = 0;
-       if (flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS)
-               a->traverse_mount_points = 0;
-       else
-               a->traverse_mount_points = 1;
        return (r);
 }
 
@@ -852,7 +840,7 @@ next_entry(struct archive_read_disk *a, struct tree *t,
        }
        if (t->initial_filesystem_id == -1)
                t->initial_filesystem_id = t->current_filesystem_id;
-       if (!a->traverse_mount_points) {
+       if (a->flags & ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS) {
                if (t->initial_filesystem_id != t->current_filesystem_id)
                        return (ARCHIVE_RETRY);
        }
@@ -1219,9 +1207,11 @@ _archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname)
        struct archive_read_disk *a = (struct archive_read_disk *)_a;
 
        if (a->tree != NULL)
-               a->tree = tree_reopen(a->tree, pathname, a->restore_time);
+               a->tree = tree_reopen(a->tree, pathname,
+                   a->flags & ARCHIVE_READDISK_RESTORE_ATIME);
        else
-               a->tree = tree_open(pathname, a->symlink_mode, a->restore_time);
+               a->tree = tree_open(pathname, a->symlink_mode,
+                   a->flags & ARCHIVE_READDISK_RESTORE_ATIME);
        if (a->tree == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate directory traversal data");
@@ -1519,7 +1509,7 @@ tree_reopen(struct tree *t, const wchar_t *path, int restore_time)
        struct archive_wstring ws;
        wchar_t *pathname, *p, *base;
 
-       t->flags = (restore_time)?needsRestoreTimes:0;
+       t->flags = (restore_time != 0)?needsRestoreTimes:0;
        t->visit_type = 0;
        t->tree_errno = 0;
        t->full_path_dir_length = 0;
index c9aca8fa985d0601b065a0911a0258df1f507ece..fdbfbec91e936ab8f24bee9f0c147855217651fa 100644 (file)
@@ -1228,8 +1228,8 @@ test_restore_atime(void)
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 
        /*
-        * Test4: Traversals with archive_read_disk_set_atime_restored() and
-        * archive_read_disk_honor_nodump().
+        * Test4: Traversals with ARCHIVE_READDISK_RESTORE_ATIME and
+        * ARCHIVE_READDISK_HONOR_NODUMP
         */
        assertNodump("at/f1");
        assertNodump("at/f2");
@@ -1460,7 +1460,7 @@ test_nodump(void)
        assert((a = archive_read_disk_new()) != NULL);
 
        /*
-        * Test1: Traversals without archive_read_disk_honor_nodump().
+        * Test1: Traversals without ARCHIVE_READDISK_HONOR_NODUMP
         */
        failure("Directory traversals should work as well");
        assertEqualIntA(a, ARCHIVE_OK, archive_read_disk_open(a, "nd"));
@@ -1513,7 +1513,7 @@ test_nodump(void)
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 
        /*
-        * Test2: Traversals with archive_read_disk_honor_nodump().
+        * Test2: Traversals with ARCHIVE_READDISK_HONOR_NODUMP
         */
        assertUtimes("nd/f1", 886600, 0, 886600, 0);
        assertUtimes("nd/f2", 886611, 0, 886611, 0);