struct archive_entry *ae;
struct archive *a;
size_t used;
- int i;
+ int i, numEntries = 0;
char *buff, *file_buff;
buff = malloc(BUFF_SIZE);
assertA(0 == archive_write_set_compression_none(a));
assertA(0 == archive_write_open_memory(a, buff, BUFF_SIZE, &used));
/* A directory to be restored with EXTRACT_PERM. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir_0775");
archive_entry_set_mode(ae, S_IFDIR | 0775);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A regular file. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "file");
archive_entry_set_mode(ae, S_IFREG | 0755);
assertA(FILE_BUFF_SIZE == archive_write_data(a, file_buff, FILE_BUFF_SIZE));
archive_entry_free(ae);
/* A directory that should obey umask when restored. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir");
archive_entry_set_mode(ae, S_IFDIR | 0777);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A file in the directory. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir/file");
archive_entry_set_mode(ae, S_IFREG | 0700);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A file in a dir that is not already in the archive. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir2/file");
archive_entry_set_mode(ae, S_IFREG | 0000);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A dir with a trailing /. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir3/.");
archive_entry_set_mode(ae, S_IFDIR | 0710);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* Multiple dirs with a single entry. */
+ ++numEntries;
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir4/a/../b/../c/");
archive_entry_set_mode(ae, S_IFDIR | 0711);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A symlink. */
- assert((ae = archive_entry_new()) != NULL);
- archive_entry_copy_pathname(ae, "symlink");
- archive_entry_set_mode(ae, AE_IFLNK | 0755);
- archive_entry_set_symlink(ae, "file");
- assertA(0 == archive_write_header(a, ae));
- archive_entry_free(ae);
+ if (canSymlink()) {
+ ++numEntries;
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "symlink");
+ archive_entry_set_mode(ae, AE_IFLNK | 0755);
+ archive_entry_set_symlink(ae, "file");
+ assertA(0 == archive_write_header(a, ae));
+ archive_entry_free(ae);
+ }
/* Close out the archive. */
assertA(0 == archive_write_close(a));
-#if ARCHIVE_VERSION_NUMBER < 2000000
- archive_write_finish(a);
-#else
assertA(0 == archive_write_finish(a));
-#endif
/* Extract the entries to disk. */
assert((a = archive_read_new()) != NULL);
assertA(0 == archive_read_next_header(a, &ae));
assertA(0 == archive_read_extract(a, ae, ARCHIVE_EXTRACT_PERM));
/* Rest of entries get restored with no flags. */
- for (i = 0; i < 7; i++) {
+ for (i = 1; i < numEntries; i++) {
failure("Error reading entry %d", i);
assertA(0 == archive_read_next_header(a, &ae));
failure("Failed to extract entry %d: %s", i,
}
assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
assert(0 == archive_read_close(a));
-#if ARCHIVE_VERSION_NUMBER < 2000000
- archive_read_finish(a);
-#else
assert(0 == archive_read_finish(a));
-#endif
-#if !defined(_WIN32) || defined(__CYGWIN__)
/* Test the entries on disk. */
/* This first entry was extracted with ARCHIVE_EXTRACT_PERM,
* so the permissions should have been restored exactly,
assertIsDir("dir4/a", 0755);
assertIsDir("dir4/b", 0755);
assertIsDir("dir4/c", 0711);
- assertIsSymlink("symlink", NULL); /* TODO: Assert value of symlink */
-#endif
+ if (canSymlink())
+ assertIsSymlink("symlink", "file");
free(buff);
free(file_buff);
struct archive_entry *ae;
int r;
+ if (!canSymlink()) {
+ skipping("Symlinks not supported");
+ return;
+ }
+
/* Write entries to disk. */
assert((ad = archive_write_disk_new()) != NULL);
/* Regular file: link1a */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "link1a");
- archive_entry_set_mode(ae, S_IFREG | 0755);
+ archive_entry_set_mode(ae, AE_IFREG | 0755);
archive_entry_set_size(ae, sizeof(data));
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
assertEqualInt(sizeof(data),
/* Symbolic Link: link1b -> link1a */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "link1b");
- archive_entry_set_mode(ae, S_IFREG | 0642);
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
archive_entry_set_size(ae, 0);
archive_entry_copy_symlink(ae, "link1a");
assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
- if (r >= ARCHIVE_WARN) {
- assertEqualInt(ARCHIVE_WARN,
- archive_write_data(ad, data, sizeof(data)));
+ if (r >= ARCHIVE_WARN)
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
- }
archive_entry_free(ae);
/*
/* Symbolic link: link2b -> link2a */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "link2b");
- archive_entry_set_mode(ae, S_IFLNK | 0642);
+ archive_entry_set_mode(ae, AE_IFLNK | 0642);
archive_entry_unset_size(ae);
archive_entry_copy_symlink(ae, "link2a");
assertEqualIntA(ad, 0, r = archive_write_header(ad, ae));
/* File: link2a */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "link2a");
- archive_entry_set_mode(ae, S_IFREG | 0755);
+ archive_entry_set_mode(ae, AE_IFREG | 0755);
archive_entry_set_size(ae, sizeof(data));
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
assertEqualInt(sizeof(data),