From: Michihiro NAKAJIMA Date: Sat, 7 Jan 2012 08:00:12 +0000 (-0500) Subject: Introduce archive_read_disk_disable_mac_copyfile() to eliminate the mac X-Git-Tag: v3.0.4~2^2~215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c5decfe67437c4a5c4adf6e55cd8f6ab1d86a43;p=thirdparty%2Flibarchive.git Introduce archive_read_disk_disable_mac_copyfile() to eliminate the mac specific code handling of a resource fork file whose filename has "._" prefix from bsdtar. SVN-Revision: 4091 --- diff --git a/libarchive/archive.h b/libarchive/archive.h index c29d6396f..a59aa1e6b 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -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 *, diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c index e0d78e0bb..8300438c0 100644 --- a/libarchive/archive_read_disk_posix.c +++ b/libarchive/archive_read_disk_posix.c @@ -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); diff --git a/libarchive/archive_read_disk_private.h b/libarchive/archive_read_disk_private.h index 293298c37..c6af738ea 100644 --- a/libarchive/archive_read_disk_private.h +++ b/libarchive/archive_read_disk_private.h @@ -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); diff --git a/libarchive/archive_read_disk_windows.c b/libarchive/archive_read_disk_windows.c index 5e3c08372..b96bfe1c7 100644 --- a/libarchive/archive_read_disk_windows.c +++ b/libarchive/archive_read_disk_windows.c @@ -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 diff --git a/tar/write.c b/tar/write.c index 551e44f20..9123753a6 100644 --- a/tar/write.c +++ b/tar/write.c @@ -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.