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)
40 // The test ACL used here is sometimes assigned to the 'Guest' user
41 // This changes the text and breaks the test. This function simply
42 // strips the 'Guest' information from the string to help ensure
43 // consistent results on different machines.
45 static char _acl_temp[256];
47 clean_acl(const char *acl) {
49 if (strlen(acl) >= sizeof(_acl_temp))
52 strcpy(_acl_temp, acl);
53 p = strstr(_acl_temp, ":Guest:");
55 fprintf(stderr, "Shortening: %s\n", p + 1);
56 memmove(p + 1, p + 6, strlen(p + 6) + 1);
57 q = strstr(p + 2, ":");
58 fprintf(stderr, "Shortening: %s\n", q);
59 memmove(p + 2, q, strlen(q) + 1);
66 has_xattr(const char *filename, const char *xattrname)
72 r = listxattr(filename, NULL, 0, XATTR_SHOWCOMPRESSION);
78 assert((nl = malloc(r)) != NULL);
82 r = listxattr(filename, nl, r, XATTR_SHOWCOMPRESSION);
89 for (nlp = nl; nlp < nl + r; nlp += strlen(nlp) + 1) {
90 if (strcmp(nlp, xattrname) == 0) {
102 * Exercise HFS+ Compression.
104 DEFINE_TEST(test_write_disk_appledouble)
106 #if !defined(__APPLE__) || !defined(UF_COMPRESSED) || !defined(HAVE_SYS_XATTR_H)\
107 || !defined(HAVE_ZLIB_H)
108 skipping("MacOS-specific AppleDouble test");
110 const char *refname = "test_write_disk_appledouble.cpio.gz";
111 struct archive *ad, *a;
112 struct archive_entry *ae;
116 extract_reference_file(refname);
119 * Extract an archive to disk with HFS+ Compression.
121 assert((ad = archive_write_disk_new()) != NULL);
122 assertEqualIntA(ad, ARCHIVE_OK,
123 archive_write_disk_set_standard_lookup(ad));
124 assertEqualIntA(ad, ARCHIVE_OK,
125 archive_write_disk_set_options(ad,
126 ARCHIVE_EXTRACT_TIME |
127 ARCHIVE_EXTRACT_SECURE_SYMLINKS |
128 ARCHIVE_EXTRACT_SECURE_NODOTDOT |
129 ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED));
131 assert((a = archive_read_new()) != NULL);
132 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
133 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
134 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
137 assertMakeDir("hfscmp", 0755);
138 assertChdir("hfscmp");
141 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
142 assertEqualString(".", archive_entry_pathname(ae));
144 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
145 assertEqualString("./file3", archive_entry_pathname(ae));
146 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
147 /* Extract ._file3 which will be merged into file3 as metadata. */
148 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
149 assertEqualString("./._file3", archive_entry_pathname(ae));
150 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
152 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
153 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
154 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
155 assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
158 assertEqualInt(0, stat("file3", &st));
159 assertEqualInt(UF_COMPRESSED, st.st_flags & UF_COMPRESSED);
160 assertFileSize("file3", 8);
161 failure("'%s' should not have Resource Fork", "file3");
162 assertEqualInt(0, has_xattr("file3", "com.apple.ResourceFork"));
163 failure("'%s' should have decompfs xattr", "file3");
164 assertEqualInt(1, has_xattr("file3", "com.apple.decmpfs"));
165 assert(NULL != (acl = acl_get_file("file3", ACL_TYPE_EXTENDED)));
166 assertEqualString(clean_acl(acl_to_text(acl, NULL)),
168 "user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA000000C9:::deny:read\n"
169 "group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050:admin:80:allow:write\n"
171 if (acl) acl_free(acl);
173 failure("'file3' should be merged and removed");
174 assertFileNotExists("._file3");
179 * Extract an archive to disk without HFS+ Compression.
181 assert((ad = archive_write_disk_new()) != NULL);
182 assertEqualIntA(ad, ARCHIVE_OK,
183 archive_write_disk_set_standard_lookup(ad));
184 assertEqualIntA(ad, ARCHIVE_OK,
185 archive_write_disk_set_options(ad,
186 ARCHIVE_EXTRACT_TIME |
187 ARCHIVE_EXTRACT_SECURE_SYMLINKS |
188 ARCHIVE_EXTRACT_SECURE_NODOTDOT));
190 assert((a = archive_read_new()) != NULL);
191 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
192 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
193 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
196 assertMakeDir("nocmp", 0755);
197 assertChdir("nocmp");
200 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
201 assertEqualString(".", archive_entry_pathname(ae));
203 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
204 assertEqualString("./file3", archive_entry_pathname(ae));
205 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
206 /* Extract ._file3 which will be merged into file3 as metadata. */
207 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
208 assertEqualString("./._file3", archive_entry_pathname(ae));
209 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
211 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
212 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
213 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
214 assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
217 assertEqualInt(0, stat("file3", &st));
218 assertEqualInt(0, st.st_flags & UF_COMPRESSED);
219 assertFileSize("file3", 8);
220 failure("'%s' should not have Resource Fork", "file3");
221 assertEqualInt(0, has_xattr("file3", "com.apple.ResourceFork"));
222 failure("'%s' should not have decmpfs", "file3");
223 assertEqualInt(0, has_xattr("file3", "com.apple.decmpfs"));
224 assert(NULL != (acl = acl_get_file("file3", ACL_TYPE_EXTENDED)));
225 assertEqualString(clean_acl(acl_to_text(acl, NULL)),
227 "user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA000000C9:::deny:read\n"
228 "group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050:admin:80:allow:write\n"
230 if (acl) acl_free(acl);
232 failure("'file3' should be merged and removed");
233 assertFileNotExists("._file3");
237 assertEqualFile("hfscmp/file3", "nocmp/file3");