]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Introduce archive_read_disk_disable_mac_copyfile() to eliminate the mac
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 7 Jan 2012 08:00:12 +0000 (03:00 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 7 Jan 2012 08:00:12 +0000 (03:00 -0500)
specific code handling of a resource fork file whose filename has "._" prefix
from bsdtar.

SVN-Revision: 4091

libarchive/archive.h
libarchive/archive_read_disk_posix.c
libarchive/archive_read_disk_private.h
libarchive/archive_read_disk_windows.c
tar/write.c

index c29d6396fef2adf1538880aa012e77c72ca24ea4..a59aa1e6b2ba69067df7bb9457bb16e8a60bbf01 100644 (file)
@@ -765,6 +765,7 @@ __LA_DECL int       archive_read_disk_current_filesystem_is_remote(struct archive *);
 /* Request that the access time of the entry visited by travesal be restored. */
 __LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
 __LA_DECL int  archive_read_disk_honor_nodump(struct archive *);
+__LA_DECL int  archive_read_disk_disable_mac_copyfile(struct archive *);
 
 __LA_DECL int  archive_read_disk_set_name_filter_callback(struct archive *,
                    int (*_name_filter_func)(struct archive *, void *,
index e0d78e0bb4aa0dc0061ee2efb742f97eb761d826..8300438c07a9c293472f17da041d917d55f78074 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2003-2009 Tim Kientzle
- * Copyright (c) 2010,2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -443,15 +443,15 @@ archive_read_disk_new(void)
 {
        struct archive_read_disk *a;
 
-       a = (struct archive_read_disk *)malloc(sizeof(*a));
+       a = (struct archive_read_disk *)calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
-       memset(a, 0, sizeof(*a));
        a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
        a->archive.state = ARCHIVE_STATE_NEW;
        a->archive.vtable = archive_read_disk_vtable();
        a->lookup_uname = trivial_lookup_uname;
        a->lookup_gname = trivial_lookup_gname;
+       a->enable_copyfile = 1;
        a->entry_wd_fd = -1;
        return (&a->archive);
 }
@@ -578,6 +578,16 @@ archive_read_disk_honor_nodump(struct archive *_a)
        return (ARCHIVE_OK);
 }
 
+int
+archive_read_disk_disable_mac_copyfile(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_disable_mac_copyfile");
+       a->enable_copyfile = 0;
+       return (ARCHIVE_OK);
+}
+
 /*
  * Trivial implementations of gname/uname lookup functions.
  * These are normally overridden by the client, but these stub
@@ -886,6 +896,18 @@ next_entry:
                }       
        } while (lst == NULL);
 
+#ifdef __APPLE__
+       if (a->enable_copyfile) {
+               /* If we're using copyfile(), ignore "._XXX" files. */
+               const char *bname = strrchr(tree_current_path(t), '/');
+               if (bname == NULL)
+                       bname = tree_current_path(t);
+               else
+                       ++bname;
+               if (bname[0] == '.' && bname[1] == '_')
+                       goto next_entry;
+       }
+#endif
        archive_entry_copy_pathname(entry, tree_current_path(t));
        if (a->name_filter_func) {
                if (!a->name_filter_func(_a, a->name_filter_data, entry))
@@ -1009,6 +1031,12 @@ next_entry:
                }
        }
 #endif
+#ifdef __APPLE__
+       if (!a->enable_copyfile) {
+               /* If we aren't using copyfile, drop the copyfile() data. */
+               archive_entry_copy_mac_metadata(entry, NULL, 0);
+       }
+#endif
 
        /* Return to the initial directory. */
        tree_enter_initial_dir(t);
index 293298c373bdb23b19d85e99042fb6e80017b58d..c6af738ea2ed0f3121bdbf0e083d0b78b93d1fcd 100644 (file)
@@ -61,6 +61,9 @@ struct archive_read_disk {
        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;
+
        int              entry_wd_fd;
 
        const char * (*lookup_gname)(void *private, int64_t gid);
index 5e3c0837202df051a03eba6506e95f9b59f618a7..b96bfe1c74bc03e23d4681b9db1128f3621945f6 100644 (file)
@@ -505,6 +505,16 @@ archive_read_disk_honor_nodump(struct archive *_a)
        return (ARCHIVE_OK);
 }
 
+int
+archive_read_disk_disable_mac_copyfile(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_disable_mac_copyfile");
+       a->enable_copyfile = 0;
+       return (ARCHIVE_OK);
+}
+
 /*
  * Trivial implementations of gname/uname lookup functions.
  * These are normally overridden by the client, but these stub
index 551e44f20d01954c2ab285b1521b5b17efc44c1b..9123753a63d854b8f9b5150f7ee1fc2ec8a154b8 100644 (file)
@@ -435,6 +435,8 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
        /* Skip a file if it has nodump flag. */
        if (bsdtar->option_honor_nodump)
                archive_read_disk_honor_nodump(bsdtar->diskreader);
+       if (!bsdtar->enable_copyfile)
+               archive_read_disk_disable_mac_copyfile(bsdtar->diskreader);
        archive_read_disk_set_standard_lookup(bsdtar->diskreader);
 
        if (bsdtar->names_from_file != NULL)
@@ -718,20 +720,6 @@ name_filter(struct archive *a, void *_data, struct archive_entry *entry)
         */
        if (lafe_excluded(bsdtar->matching, archive_entry_pathname(entry)))
                return (0);
-
-#ifdef __APPLE__
-       if (bsdtar->enable_copyfile) {
-               /* If we're using copyfile(), ignore "._XXX" files. */
-               const char *bname = strrchr(
-                       archive_entry_pathname(entry), '/');
-               if (bname == NULL)
-                       bname = name;
-               else
-                       ++bname;
-               if (bname[0] == '.' && bname[1] == '_')
-                       return (0);
-       }
-#endif
        return (1);
 }
 
@@ -849,14 +837,6 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
                if (bsdtar->gname)
                        archive_entry_set_gname(entry, bsdtar->gname);
 
-#ifdef __APPLE__
-               if (!bsdtar->enable_copyfile) {
-                       /* If we aren't using copyfile, drop the copyfile()
-                        * data. */
-                       archive_entry_copy_mac_metadata(entry, NULL, 0);
-               }
-#endif
-
                /*
                 * Rewrite the pathname to be archived.  If rewrite
                 * fails, skip the entry.