2 * Copyright (c) 2003-2010 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 __FBSDID("$FreeBSD$");
28 /* The sample has some files in a directory with a very long name. */
29 #define TESTPATH "abcdefghijklmnopqrstuvwxyz/" \
30 "abcdefghijklmnopqrstuvwxyz/" \
31 "abcdefghijklmnopqrstuvwxyz/" \
32 "abcdefghijklmnopqrstuvwxyz/" \
33 "abcdefghijklmnopqrstuvwxyz/" \
34 "abcdefghijklmnopqrstuvwxyz/" \
35 "abcdefghijklmnopqrstuvwxyz/"
37 static void test_compat_mac_1(void);
38 static void test_compat_mac_2(void);
41 * Apple shipped an extended version of GNU tar with Mac OS X 10.5
45 test_compat_mac_1(void)
47 char name[] = "test_compat_mac-1.tar.Z";
48 struct archive_entry *ae;
53 assert((a = archive_read_new()) != NULL);
54 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
55 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
56 assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "mac-ext"));
57 extract_reference_file(name);
58 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
60 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
61 assertEqualString(TESTPATH, archive_entry_pathname(ae));
62 assertEqualInt(1275688109, archive_entry_mtime(ae));
63 assertEqualInt(95594, archive_entry_uid(ae));
64 assertEqualString("kientzle", archive_entry_uname(ae));
65 assertEqualInt(5000, archive_entry_gid(ae));
66 assertEqualString("", archive_entry_gname(ae));
67 assertEqualInt(040755, archive_entry_mode(ae));
69 attr = archive_entry_mac_metadata(ae, &attrSize);
71 assertEqualInt(0, attrSize);
73 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
74 assertEqualString(TESTPATH "dir/", archive_entry_pathname(ae));
75 assertEqualInt(1275687611, archive_entry_mtime(ae));
76 assertEqualInt(95594, archive_entry_uid(ae));
77 assertEqualString("kientzle", archive_entry_uname(ae));
78 assertEqualInt(5000, archive_entry_gid(ae));
79 assertEqualString("", archive_entry_gname(ae));
80 assertEqualInt(040755, archive_entry_mode(ae));
82 attr = archive_entry_mac_metadata(ae, &attrSize);
84 assertEqualInt(225, attrSize);
86 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
87 assertEqualString(TESTPATH "file", archive_entry_pathname(ae));
88 assertEqualInt(1275687588, archive_entry_mtime(ae));
89 assertEqualInt(95594, archive_entry_uid(ae));
90 assertEqualString("kientzle", archive_entry_uname(ae));
91 assertEqualInt(5000, archive_entry_gid(ae));
92 assertEqualString("", archive_entry_gname(ae));
93 assertEqualInt(0100644, archive_entry_mode(ae));
95 attr = archive_entry_mac_metadata(ae, &attrSize);
97 assertEqualInt(225, attrSize);
99 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
100 assertEqualString("dir/", archive_entry_pathname(ae));
101 assertEqualInt(1275688064, archive_entry_mtime(ae));
102 assertEqualInt(95594, archive_entry_uid(ae));
103 assertEqualString("kientzle", archive_entry_uname(ae));
104 assertEqualInt(5000, archive_entry_gid(ae));
105 assertEqualString("", archive_entry_gname(ae));
106 assertEqualInt(040755, archive_entry_mode(ae));
108 attr = archive_entry_mac_metadata(ae, &attrSize);
109 assert(attr != NULL);
110 assertEqualInt(225, attrSize);
111 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
113 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
114 assertEqualString("file", archive_entry_pathname(ae));
115 assertEqualInt(1275625860, archive_entry_mtime(ae));
116 assertEqualInt(95594, archive_entry_uid(ae));
117 assertEqualString("kientzle", archive_entry_uname(ae));
118 assertEqualInt(5000, archive_entry_gid(ae));
119 assertEqualString("", archive_entry_gname(ae));
120 assertEqualInt(0100644, archive_entry_mode(ae));
122 attr = archive_entry_mac_metadata(ae, &attrSize);
123 assert(attr != NULL);
124 assertEqualInt(225, attrSize);
125 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
127 /* Verify the end-of-archive. */
128 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
130 /* Verify that the format detection worked. */
131 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
132 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR);
134 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
135 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
139 * Apple shipped a customized version of bsdtar starting with MacOS 10.6.
142 test_compat_mac_2(void)
144 char name[] = "test_compat_mac-2.tar.Z";
145 struct archive_entry *ae;
150 assert((a = archive_read_new()) != NULL);
151 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
152 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
153 assertEqualIntA(a, ARCHIVE_OK, archive_read_set_options(a, "mac-ext"));
154 extract_reference_file(name);
155 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
157 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
158 assertEqualString("./", archive_entry_pathname(ae));
159 assertEqualInt(1303628303, archive_entry_mtime(ae));
160 assertEqualInt(501, archive_entry_uid(ae));
161 assertEqualString("tim", archive_entry_uname(ae));
162 assertEqualInt(20, archive_entry_gid(ae));
163 assertEqualString("staff", archive_entry_gname(ae));
164 assertEqualInt(040755, archive_entry_mode(ae));
166 attr = archive_entry_mac_metadata(ae, &attrSize);
167 assert(attr == NULL);
168 assertEqualInt(0, attrSize);
170 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
171 assertEqualString("./mydir/", archive_entry_pathname(ae));
172 assertEqualInt(1303628303, archive_entry_mtime(ae));
173 assertEqualInt(501, archive_entry_uid(ae));
174 assertEqualString("tim", archive_entry_uname(ae));
175 assertEqualInt(20, archive_entry_gid(ae));
176 assertEqualString("staff", archive_entry_gname(ae));
177 assertEqualInt(040755, archive_entry_mode(ae));
179 attr = archive_entry_mac_metadata(ae, &attrSize);
180 assert(attr != NULL);
181 assertEqualInt(267, attrSize);
182 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
184 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
185 assertEqualString("./myfile", archive_entry_pathname(ae));
186 assertEqualInt(1303628303, archive_entry_mtime(ae));
187 assertEqualInt(501, archive_entry_uid(ae));
188 assertEqualString("tim", archive_entry_uname(ae));
189 assertEqualInt(20, archive_entry_gid(ae));
190 assertEqualString("staff", archive_entry_gname(ae));
191 assertEqualInt(0100644, archive_entry_mode(ae));
193 attr = archive_entry_mac_metadata(ae, &attrSize);
194 assert(attr != NULL);
195 assertEqualInt(267, attrSize);
196 assertEqualMem("\x00\x05\x16\x07\x00\x02\x00\x00Mac OS X", attr, 16);
198 /* Verify the end-of-archive. */
199 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
201 /* Verify that the format detection worked. */
202 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
203 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
205 assertEqualInt(ARCHIVE_OK, archive_read_close(a));
206 assertEqualInt(ARCHIVE_OK, archive_read_free(a));
209 DEFINE_TEST(test_compat_mac)