2
* Copyright (c) 2003-2007 Tim Kientzle
3
* Copyright (c) 2009 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: head/lib/libarchive/test/test_read_format_isorr_rr_moved.c 201247 2009-12-30 05:59:21Z kientzle $");
30
Execute the following command to rebuild the data for this program:
31
tail -n +32 test_read_format_isorr_rr_moved.c | /bin/sh
35
mkdir -p $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10
36
echo "hello" >$dirname/file
37
dd if=/dev/zero count=1 bs=12345678 >>$dirname/file
38
deepfile=$dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/deep
39
echo "hello" >$deepfile
40
dd if=/dev/zero count=1 bs=12345678 >>$deepfile
41
time="197001020000.01"
42
TZ=utc touch -afhm -t $time $deepfile
43
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10
44
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9
45
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8
46
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6/dir7
47
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5/dir6
48
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4/dir5
49
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3/dir4
50
TZ=utc touch -afhm -t $time $dirname/dir1/dir2/dir3
51
TZ=utc touch -afhm -t $time $dirname/dir1/dir2
52
TZ=utc touch -afhm -t $time $dirname/dir1
53
TZ=utc touch -afhm -t $time $dirname/file
54
TZ=utc touch -afhm -t $time $dirname
55
F=test_read_format_isorr_rockridge_moved.iso.Z
56
mkhybrid -R -uid 1 -gid 2 $dirname | compress > $F
57
uuencode $F $F > $F.uu
61
DEFINE_TEST(test_read_format_isorr_rr_moved)
63
const char *refname = "test_read_format_iso_rockridge_rr_moved.iso.Z";
64
struct archive_entry *ae;
71
extract_reference_file(refname);
72
assert((a = archive_read_new()) != NULL);
73
assertEqualInt(0, archive_read_support_compression_all(a));
74
assertEqualInt(0, archive_read_support_format_all(a));
75
assertEqualInt(ARCHIVE_OK,
76
archive_read_open_filename(a, refname, 10240));
78
/* Retrieve each of the 8 files on the ISO image and
79
* verify that each one is what we expect. */
80
for (i = 0; i < 13; ++i) {
81
assertEqualInt(0, archive_read_next_header(a, &ae));
83
if (strcmp(".", archive_entry_pathname(ae)) == 0) {
84
/* '.' root directory. */
85
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
86
assertEqualInt(2048, archive_entry_size(ae));
87
/* Now, we read timestamp recorded by RRIP "TF". */
88
assertEqualInt(86401, archive_entry_mtime(ae));
89
assertEqualInt(0, archive_entry_mtime_nsec(ae));
90
/* Now, we read links recorded by RRIP "PX". */
91
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
92
assertEqualInt(1, archive_entry_uid(ae));
93
assertEqualIntA(a, ARCHIVE_EOF,
94
archive_read_data_block(a, &p, &size, &offset));
95
assertEqualInt((int)size, 0);
96
} else if (strcmp("dir1", archive_entry_pathname(ae)) == 0) {
98
assertEqualString("dir1", archive_entry_pathname(ae));
99
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
100
assertEqualInt(2048, archive_entry_size(ae));
101
assertEqualInt(86401, archive_entry_mtime(ae));
102
assertEqualInt(86401, archive_entry_atime(ae));
103
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
104
assertEqualInt(1, archive_entry_uid(ae));
105
assertEqualInt(2, archive_entry_gid(ae));
106
} else if (strcmp("dir1/dir2",
107
archive_entry_pathname(ae)) == 0) {
109
assertEqualString("dir1/dir2",
110
archive_entry_pathname(ae));
111
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
112
assertEqualInt(2048, archive_entry_size(ae));
113
assertEqualInt(86401, archive_entry_mtime(ae));
114
assertEqualInt(86401, archive_entry_atime(ae));
115
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
116
assertEqualInt(1, archive_entry_uid(ae));
117
assertEqualInt(2, archive_entry_gid(ae));
118
} else if (strcmp("dir1/dir2/dir3",
119
archive_entry_pathname(ae)) == 0) {
121
assertEqualString("dir1/dir2/dir3",
122
archive_entry_pathname(ae));
123
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
124
assertEqualInt(2048, archive_entry_size(ae));
125
assertEqualInt(86401, archive_entry_mtime(ae));
126
assertEqualInt(86401, archive_entry_atime(ae));
127
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
128
assertEqualInt(1, archive_entry_uid(ae));
129
assertEqualInt(2, archive_entry_gid(ae));
130
} else if (strcmp("dir1/dir2/dir3/dir4",
131
archive_entry_pathname(ae)) == 0) {
133
assertEqualString("dir1/dir2/dir3/dir4",
134
archive_entry_pathname(ae));
135
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
136
assertEqualInt(2048, archive_entry_size(ae));
137
assertEqualInt(86401, archive_entry_mtime(ae));
138
assertEqualInt(86401, archive_entry_atime(ae));
139
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
140
assertEqualInt(1, archive_entry_uid(ae));
141
assertEqualInt(2, archive_entry_gid(ae));
142
} else if (strcmp("dir1/dir2/dir3/dir4/dir5",
143
archive_entry_pathname(ae)) == 0) {
145
assertEqualString("dir1/dir2/dir3/dir4/dir5",
146
archive_entry_pathname(ae));
147
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
148
assertEqualInt(2048, archive_entry_size(ae));
149
assertEqualInt(86401, archive_entry_mtime(ae));
150
assertEqualInt(86401, archive_entry_atime(ae));
151
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
152
assertEqualInt(1, archive_entry_uid(ae));
153
assertEqualInt(2, archive_entry_gid(ae));
154
} else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6",
155
archive_entry_pathname(ae)) == 0) {
157
assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6",
158
archive_entry_pathname(ae));
159
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
160
assertEqualInt(2048, archive_entry_size(ae));
161
assertEqualInt(86401, archive_entry_mtime(ae));
162
assertEqualInt(86401, archive_entry_atime(ae));
163
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
164
assertEqualInt(1, archive_entry_uid(ae));
165
assertEqualInt(2, archive_entry_gid(ae));
166
} else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7",
167
archive_entry_pathname(ae)) == 0) {
169
assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7",
170
archive_entry_pathname(ae));
171
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
172
assertEqualInt(2048, archive_entry_size(ae));
173
assertEqualInt(86401, archive_entry_mtime(ae));
174
assertEqualInt(86401, archive_entry_atime(ae));
175
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
176
assertEqualInt(1, archive_entry_uid(ae));
177
assertEqualInt(2, archive_entry_gid(ae));
178
} else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
180
archive_entry_pathname(ae)) == 0) {
182
assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
184
archive_entry_pathname(ae));
185
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
186
assertEqualInt(2048, archive_entry_size(ae));
187
assertEqualInt(86401, archive_entry_mtime(ae));
188
assertEqualInt(86401, archive_entry_atime(ae));
189
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
190
assertEqualInt(1, archive_entry_uid(ae));
191
assertEqualInt(2, archive_entry_gid(ae));
192
} else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
194
archive_entry_pathname(ae)) == 0) {
196
assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
198
archive_entry_pathname(ae));
199
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
200
assertEqualInt(2048, archive_entry_size(ae));
201
assertEqualInt(86401, archive_entry_mtime(ae));
202
assertEqualInt(86401, archive_entry_atime(ae));
203
assertEqualInt(3, archive_entry_stat(ae)->st_nlink);
204
assertEqualInt(1, archive_entry_uid(ae));
205
assertEqualInt(2, archive_entry_gid(ae));
206
} else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
208
archive_entry_pathname(ae)) == 0) {
210
assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
212
archive_entry_pathname(ae));
213
assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
214
assertEqualInt(2048, archive_entry_size(ae));
215
assertEqualInt(86401, archive_entry_mtime(ae));
216
assertEqualInt(86401, archive_entry_atime(ae));
217
assertEqualInt(2, archive_entry_stat(ae)->st_nlink);
218
assertEqualInt(1, archive_entry_uid(ae));
219
assertEqualInt(2, archive_entry_gid(ae));
220
} else if (strcmp("file", archive_entry_pathname(ae)) == 0) {
221
/* A regular file. */
222
assertEqualString("file", archive_entry_pathname(ae));
223
assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
224
assertEqualInt(12345684, archive_entry_size(ae));
226
archive_read_data_block(a, &p, &size, &offset));
227
assertEqualInt(0, offset);
228
assertEqualMem(p, "hello\n", 6);
229
assertEqualInt(86401, archive_entry_mtime(ae));
230
assertEqualInt(86401, archive_entry_atime(ae));
231
assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
232
assertEqualInt(1, archive_entry_uid(ae));
233
assertEqualInt(2, archive_entry_gid(ae));
234
} else if (strcmp("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
235
"/dir8/dir9/dir10/deep",
236
archive_entry_pathname(ae)) == 0) {
237
/* A regular file. */
238
assertEqualString("dir1/dir2/dir3/dir4/dir5/dir6/dir7"
239
"/dir8/dir9/dir10/deep",
240
archive_entry_pathname(ae));
241
assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
242
assertEqualInt(12345684, archive_entry_size(ae));
244
archive_read_data_block(a, &p, &size, &offset));
245
assertEqualInt(0, offset);
246
assertEqualMem(p, "hello\n", 6);
247
assertEqualInt(86401, archive_entry_mtime(ae));
248
assertEqualInt(86401, archive_entry_atime(ae));
249
assertEqualInt(1, archive_entry_stat(ae)->st_nlink);
250
assertEqualInt(1, archive_entry_uid(ae));
251
assertEqualInt(2, archive_entry_gid(ae));
253
failure("Saw a file that shouldn't have been there");
254
assertEqualString(archive_entry_pathname(ae), "");
258
/* End of archive. */
259
assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
261
/* Verify archive format. */
262
assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS);
263
assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE);
265
/* Close the archive. */
266
assertEqualInt(0, archive_read_close(a));
267
assertEqualInt(0, archive_read_finish(a));