47
45
failure("%s", msg);
48
46
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
49
47
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
50
#if ARCHIVE_VERSION_NUMBER < 2000000
51
archive_write_finish(ad);
53
assertEqualInt(0, archive_write_finish(ad));
48
assertEqualInt(0, archive_write_free(ad));
55
50
/* Test the entries on disk. */
56
51
assert(0 == stat(archive_entry_pathname(ae), &st));
57
52
failure("%s", msg);
97
92
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
98
93
assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data)));
99
94
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
100
#if ARCHIVE_VERSION_NUMBER < 2000000
101
archive_write_finish(ad);
103
assertEqualInt(0, archive_write_finish(ad));
95
assertEqualInt(0, archive_write_free(ad));
105
97
/* Test the entries on disk. */
106
98
assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777);
107
99
assertFileSize(archive_entry_pathname(ae), sizeof(data));
136
128
archive_write_data_block(ad, data + i, 1000, i));
138
130
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
139
assertEqualInt(0, archive_write_finish(ad));
131
assertEqualInt(0, archive_write_free(ad));
141
133
/* Test the entries on disk. */
142
134
assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777);
159
151
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
160
152
assertEqualInt(5, archive_write_data(ad, data, sizeof(data)));
161
153
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
162
#if ARCHIVE_VERSION_NUMBER < 2000000
163
archive_write_finish(ad);
165
assertEqualInt(0, archive_write_finish(ad));
154
assertEqualInt(0, archive_write_free(ad));
167
156
/* Test the entry on disk. */
168
157
assert(0 == stat(archive_entry_pathname(ae), &st));
169
158
failure("st.st_mode=%o archive_entry_mode(ae)=%o",
188
177
assertEqualInt(ARCHIVE_OK,
189
178
archive_write_data_block(ad, data, sizeof(data), 0));
190
179
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
191
#if ARCHIVE_VERSION_NUMBER < 2000000
192
archive_write_finish(ad);
194
assertEqualInt(0, archive_write_finish(ad));
180
assertEqualInt(0, archive_write_free(ad));
196
182
/* Test the entry on disk. */
197
183
assert(0 == stat(archive_entry_pathname(ae), &st));
198
184
failure("st.st_mode=%o archive_entry_mode(ae)=%o",
210
196
static const char data[]="abcdefghijklmnopqrstuvwxyz";
211
197
struct archive *ad;
216
202
/* Write the entry to disk. */
217
203
assert((ad = archive_write_disk_new()) != NULL);
218
archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME);
204
archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME);
219
205
failure("%s", msg);
220
206
archive_entry_set_size(ae, sizeof(data));
221
207
archive_entry_set_mtime(ae, 123456789, 0);
222
208
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
223
209
assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data)));
224
210
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
225
#if ARCHIVE_VERSION_NUMBER < 2000000
226
archive_write_finish(ad);
228
assertEqualInt(0, archive_write_finish(ad));
211
assertEqualInt(0, archive_write_free(ad));
230
213
/* Test the entries on disk. */
231
l = strlen(archive_entry_pathname(ae));
232
fname = malloc(l + 1);
214
l = wcslen(archive_entry_pathname_w(ae));
215
fname = malloc((l + 1) * sizeof(wchar_t));
233
216
assert(NULL != fname);
234
strcpy(fname, archive_entry_pathname(ae));
217
wcscpy(fname, archive_entry_pathname_w(ae));
219
/* Skip leading drive letter from archives created
221
if (((p[0] >= L'a' && p[0] <= L'z') ||
222
(p[0] >= L'A' && p[0] <= L'Z')) &&
223
p[1] == L':' && p[2] == L'\\') {
235
226
/* Replace unusable characters in Windows to '_' */
236
for (p = fname; *p != '\0'; p++)
237
if (*p == ':' || *p == '*' || *p == '?' ||
238
*p == '"' || *p == '<' || *p == '>' || *p == '|')
227
for (; *p != L'\0'; p++)
228
if (*p == L':' || *p == L'*' || *p == L'?' ||
229
*p == L'"' || *p == L'<' || *p == L'>' || *p == L'|')
240
assert(0 == stat(fname, &st));
231
assert(0 == _wstat(fname, &st));
241
232
failure("st.st_mode=%o archive_entry_mode(ae)=%o",
242
233
st.st_mode, archive_entry_mode(ae));
243
234
assertEqualInt(st.st_size, sizeof(data));
245
237
#endif /* _WIN32 && !__CYGWIN__ */
248
239
DEFINE_TEST(test_write_disk)
250
#if ARCHIVE_VERSION_NUMBER < 1009000
251
skipping("archive_write_disk interface");
253
241
struct archive_entry *ae;
242
#if defined(_WIN32) && !defined(__CYGWIN__)
255
247
/* Force the umask to something predictable. */
256
248
assertUmask(UMASK);
314
306
#if defined(_WIN32) && !defined(__CYGWIN__)
315
307
/* A file with unusable characters in its file name. */
316
308
assert((ae = archive_entry_new()) != NULL);
317
archive_entry_copy_pathname(ae, "f:i*l?e\"f<i>l|e");
309
archive_entry_copy_pathname_w(ae, L"f:i*l?e\"f<i>l|e");
318
310
archive_entry_set_mode(ae, S_IFREG | 0755);
319
311
create_reg_file_win(ae, "Test creating a regular file"
320
312
" with unusable characters in its file name");
323
315
/* A file with unusable characters in its directory name. */
324
316
assert((ae = archive_entry_new()) != NULL);
325
archive_entry_copy_pathname(ae, "d:i*r?e\"c<t>o|ry/file1");
326
archive_entry_set_mode(ae, S_IFREG | 0755);
327
create_reg_file_win(ae, "Test creating a regular file"
328
" with unusable characters in its file name");
329
archive_entry_free(ae);
317
archive_entry_copy_pathname_w(ae, L"d:i*r?e\"c<t>o|ry/file1");
318
archive_entry_set_mode(ae, S_IFREG | 0755);
319
create_reg_file_win(ae, "Test creating a regular file"
320
" with unusable characters in its file name");
321
archive_entry_free(ae);
323
/* A full-path file with unusable characters in its file name. */
324
assert((l = GetCurrentDirectoryW(0, NULL)) != 0);
325
assert((fullpath = malloc((l + 20) * sizeof(wchar_t))) != NULL);
326
assert((l = GetCurrentDirectoryW(l, fullpath)) != 0);
327
wcscat(fullpath, L"\\f:i*l?e\"f<i>l|e");
328
assert((ae = archive_entry_new()) != NULL);
329
archive_entry_copy_pathname_w(ae, fullpath);
330
archive_entry_set_mode(ae, S_IFREG | 0755);
331
create_reg_file_win(ae, "Test creating a regular file"
332
" with unusable characters in its file name");
333
archive_entry_free(ae);
336
/* A full-path file with unusable characters in its directory name. */
337
assert((l = GetCurrentDirectoryW(0, NULL)) != 0);
338
assert((fullpath = malloc((l + 30) * sizeof(wchar_t))) != NULL);
339
assert((l = GetCurrentDirectoryW(l, fullpath)) != 0);
340
wcscat(fullpath, L"\\d:i*r?e\"c<t>o|ry/file1");
341
assert((ae = archive_entry_new()) != NULL);
342
archive_entry_copy_pathname_w(ae, fullpath);
343
archive_entry_set_mode(ae, S_IFREG | 0755);
344
create_reg_file_win(ae, "Test creating a regular file"
345
" with unusable characters in its file name");
346
archive_entry_free(ae);
330
348
#endif /* _WIN32 && !__CYGWIN__ */