2 * Copyright (c) 2003-2007 Tim Kientzle
3 * Copyright (c) 2012 Michihiro NAKAJIMA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 __FBSDID("$FreeBSD$");
32 #ifdef HAVE_SYS_XATTR_H
33 #include <sys/xattr.h>
36 #if defined(__APPLE__) && defined(UF_COMPRESSED) && defined(HAVE_SYS_XATTR_H)\
37 && defined(HAVE_ZLIB_H)
39 has_xattr(const char *filename, const char *xattrname)
45 r = listxattr(filename, NULL, 0, XATTR_SHOWCOMPRESSION);
52 if (!assert(nl != NULL))
55 r = listxattr(filename, nl, r, XATTR_SHOWCOMPRESSION);
62 for (nlp = nl; nlp < nl + r; nlp += strlen(nlp) + 1) {
63 if (strcmp(nlp, xattrname) == 0) {
75 * Exercise HFS+ Compression.
77 DEFINE_TEST(test_write_disk_mac_metadata)
79 #if !defined(__APPLE__) || !defined(UF_COMPRESSED) || !defined(HAVE_SYS_XATTR_H)\
80 || !defined(HAVE_ZLIB_H)
81 skipping("MacOS-specific Mac Metadata test");
83 const char *refname = "test_write_disk_mac_metadata.tar.gz";
84 struct archive *ad, *a;
85 struct archive_entry *ae;
89 extract_reference_file(refname);
92 * Extract an archive to disk with HFS+ Compression.
94 assert((ad = archive_write_disk_new()) != NULL);
95 assertEqualIntA(ad, ARCHIVE_OK,
96 archive_write_disk_set_standard_lookup(ad));
97 assertEqualIntA(ad, ARCHIVE_OK,
98 archive_write_disk_set_options(ad,
99 ARCHIVE_EXTRACT_TIME |
100 ARCHIVE_EXTRACT_SECURE_SYMLINKS |
101 ARCHIVE_EXTRACT_SECURE_NODOTDOT |
102 ARCHIVE_EXTRACT_MAC_METADATA));
104 assert((a = archive_read_new()) != NULL);
105 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
106 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
107 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
110 assertMakeDir("hfscmp", 0755);
111 assertChdir("hfscmp");
114 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
115 assertEqualString("file3", archive_entry_pathname(ae));
116 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
118 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
119 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
120 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
121 assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
124 assertEqualInt(0, stat("file3", &st));
125 assertEqualInt(UF_COMPRESSED, st.st_flags & UF_COMPRESSED);
126 assertFileSize("file3", 8);
127 failure("'%s' should not have Resource Fork", "file3");
128 assertEqualInt(0, has_xattr("file3", "com.apple.ResourceFork"));
129 failure("'%s' should have decompfs xattr", "file3");
130 assertEqualInt(1, has_xattr("file3", "com.apple.decmpfs"));
131 assert(NULL != (acl = acl_get_file("file3", ACL_TYPE_EXTENDED)));
132 assertEqualString(acl_to_text(acl, NULL),
134 "user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA000000C9:Guest:201:deny:read\n"
135 "group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050:admin:80:allow:write\n"
137 if (acl) acl_free(acl);
142 * Extract an archive to disk without HFS+ Compression.
144 assert((ad = archive_write_disk_new()) != NULL);
145 assertEqualIntA(ad, ARCHIVE_OK,
146 archive_write_disk_set_standard_lookup(ad));
147 assertEqualIntA(ad, ARCHIVE_OK,
148 archive_write_disk_set_options(ad,
149 ARCHIVE_EXTRACT_TIME |
150 ARCHIVE_EXTRACT_SECURE_SYMLINKS |
151 ARCHIVE_EXTRACT_SECURE_NODOTDOT |
152 ARCHIVE_EXTRACT_MAC_METADATA |
153 ARCHIVE_EXTRACT_NO_HFS_COMPRESSION));
155 assert((a = archive_read_new()) != NULL);
156 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
157 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
158 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
161 assertMakeDir("nocmp", 0755);
162 assertChdir("nocmp");
165 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
166 assertEqualString("file3", archive_entry_pathname(ae));
167 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
169 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
170 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
171 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
172 assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
175 assertEqualInt(0, stat("file3", &st));
176 assertEqualInt(0, st.st_flags & UF_COMPRESSED);
177 assertFileSize("file3", 8);
178 failure("'%s' should not have Resource Fork", "file3");
179 assertEqualInt(0, has_xattr("file3", "com.apple.ResourceFork"));
180 failure("'%s' should not have decmpfs", "file3");
181 assertEqualInt(0, has_xattr("file3", "com.apple.decmpfs"));
182 assert(NULL != (acl = acl_get_file("file3", ACL_TYPE_EXTENDED)));
183 assertEqualString(acl_to_text(acl, NULL),
185 "user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA000000C9:Guest:201:deny:read\n"
186 "group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050:admin:80:allow:write\n"
188 if (acl) acl_free(acl);
192 assertEqualFile("hfscmp/file3", "nocmp/file3");