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_appledouble)
79 #if !defined(__APPLE__) || !defined(UF_COMPRESSED) || !defined(HAVE_SYS_XATTR_H)\
80 || !defined(HAVE_ZLIB_H)
81 skipping("MacOS-specific AppleDouble test");
83 const char *refname = "test_write_disk_appledouble.cpio.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_HFS_COMPRESSION_FORCED));
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(".", archive_entry_pathname(ae));
117 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
118 assertEqualString("./file3", archive_entry_pathname(ae));
119 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
120 /* Extract ._file3 which will be merged into file3 as medtadata. */
121 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
122 assertEqualString("./._file3", archive_entry_pathname(ae));
123 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
125 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
126 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
127 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
128 assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
131 assertEqualInt(0, stat("file3", &st));
132 assertEqualInt(UF_COMPRESSED, st.st_flags & UF_COMPRESSED);
133 assertFileSize("file3", 8);
134 failure("'%s' should not have Resource Fork", "file3");
135 assertEqualInt(0, has_xattr("file3", "com.apple.ResourceFork"));
136 failure("'%s' should have decompfs xattr", "file3");
137 assertEqualInt(1, has_xattr("file3", "com.apple.decmpfs"));
138 assert(NULL != (acl = acl_get_file("file3", ACL_TYPE_EXTENDED)));
139 assertEqualString(acl_to_text(acl, NULL),
141 "user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA000000C9:Guest:201:deny:read\n"
142 "group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050:admin:80:allow:write\n"
144 if (acl) acl_free(acl);
146 failure("'file3' should be merged and removed");
147 assertFileNotExists("._file3");
152 * Extract an archive to disk without HFS+ Compression.
154 assert((ad = archive_write_disk_new()) != NULL);
155 assertEqualIntA(ad, ARCHIVE_OK,
156 archive_write_disk_set_standard_lookup(ad));
157 assertEqualIntA(ad, ARCHIVE_OK,
158 archive_write_disk_set_options(ad,
159 ARCHIVE_EXTRACT_TIME |
160 ARCHIVE_EXTRACT_SECURE_SYMLINKS |
161 ARCHIVE_EXTRACT_SECURE_NODOTDOT));
163 assert((a = archive_read_new()) != NULL);
164 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
165 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
166 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
169 assertMakeDir("nocmp", 0755);
170 assertChdir("nocmp");
173 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
174 assertEqualString(".", archive_entry_pathname(ae));
176 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
177 assertEqualString("./file3", archive_entry_pathname(ae));
178 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
179 /* Extract ._file3 which will be merged into file3 as medtadata. */
180 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
181 assertEqualString("./._file3", archive_entry_pathname(ae));
182 assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
184 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
185 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
186 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
187 assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
190 assertEqualInt(0, stat("file3", &st));
191 assertEqualInt(0, st.st_flags & UF_COMPRESSED);
192 assertFileSize("file3", 8);
193 failure("'%s' should not have Resource Fork", "file3");
194 assertEqualInt(0, has_xattr("file3", "com.apple.ResourceFork"));
195 failure("'%s' should not have decmpfs", "file3");
196 assertEqualInt(0, has_xattr("file3", "com.apple.decmpfs"));
197 assert(NULL != (acl = acl_get_file("file3", ACL_TYPE_EXTENDED)));
198 assertEqualString(acl_to_text(acl, NULL),
200 "user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA000000C9:Guest:201:deny:read\n"
201 "group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050:admin:80:allow:write\n"
203 if (acl) acl_free(acl);
205 failure("'file3' should be merged and removed");
206 assertFileNotExists("._file3");
210 assertEqualFile("hfscmp/file3", "nocmp/file3");