summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/test/test_write_disk.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2008-09-05 06:13:11 +0000
committerkientzle <kientzle@FreeBSD.org>2008-09-05 06:13:11 +0000
commit5290cd20ad8870351f499170163f9f1d27cf4c4a (patch)
treef26bca05c3fe785f6ab102b024f772ec20aba333 /lib/libarchive/test/test_write_disk.c
parent88514167fd6e746fb46c7475739be2223186c9ba (diff)
downloadFreeBSD-src-5290cd20ad8870351f499170163f9f1d27cf4c4a.zip
FreeBSD-src-5290cd20ad8870351f499170163f9f1d27cf4c4a.tar.gz
MfP4: Handle entries with unset size properly: Regular files with
unspecified size are "unlimited" (required by Zip reader, which sometimes does not know the uncompressed size of an entry until it gets to the end). Also, hardlinks with unspecified (or zero) size do not overwrite the data on disk nor do they set metadata. This is compatible with GNU tar and NetBSD pax behavior.
Diffstat (limited to 'lib/libarchive/test/test_write_disk.c')
-rw-r--r--lib/libarchive/test/test_write_disk.c71
1 files changed, 70 insertions, 1 deletions
diff --git a/lib/libarchive/test/test_write_disk.c b/lib/libarchive/test/test_write_disk.c
index 41eb1d8..b91288b 100644
--- a/lib/libarchive/test/test_write_disk.c
+++ b/lib/libarchive/test/test_write_disk.c
@@ -84,7 +84,7 @@ static void create_reg_file(struct archive_entry *ae, const char *msg)
* the entry being a maximum size.
*/
archive_entry_set_size(ae, sizeof(data));
- archive_entry_set_mtime(ae, 123456789, 0);
+ archive_entry_set_mtime(ae, 123456789, 0);
assertEqualIntA(ad, 0, archive_write_header(ad, ae));
assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data)));
assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
@@ -152,6 +152,61 @@ static void create_reg_file2(struct archive_entry *ae, const char *msg)
free(compare);
free(data);
}
+
+static void create_reg_file3(struct archive_entry *ae, const char *msg)
+{
+ static const char data[]="abcdefghijklmnopqrstuvwxyz";
+ struct archive *ad;
+ struct stat st;
+
+ /* Write the entry to disk. */
+ assert((ad = archive_write_disk_new()) != NULL);
+ failure("%s", msg);
+ /* Set the size smaller than the data and verify the truncation. */
+ archive_entry_set_size(ae, 5);
+ assertEqualIntA(ad, 0, archive_write_header(ad, ae));
+ assertEqualInt(5, archive_write_data(ad, data, sizeof(data)));
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+#if ARCHIVE_VERSION_NUMBER < 2000000
+ archive_write_finish(ad);
+#else
+ assertEqualInt(0, archive_write_finish(ad));
+#endif
+ /* Test the entry on disk. */
+ assert(0 == stat(archive_entry_pathname(ae), &st));
+ failure("st.st_mode=%o archive_entry_mode(ae)=%o",
+ st.st_mode, archive_entry_mode(ae));
+ assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK));
+ assertEqualInt(st.st_size, 5);
+}
+
+
+static void create_reg_file4(struct archive_entry *ae, const char *msg)
+{
+ static const char data[]="abcdefghijklmnopqrstuvwxyz";
+ struct archive *ad;
+ struct stat st;
+
+ /* Write the entry to disk. */
+ assert((ad = archive_write_disk_new()) != NULL);
+ /* Leave the size unset. The data should not be truncated. */
+ assertEqualIntA(ad, 0, archive_write_header(ad, ae));
+ assertEqualInt(ARCHIVE_OK,
+ archive_write_data_block(ad, data, sizeof(data), 0));
+ assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
+#if ARCHIVE_VERSION_NUMBER < 2000000
+ archive_write_finish(ad);
+#else
+ assertEqualInt(0, archive_write_finish(ad));
+#endif
+ /* Test the entry on disk. */
+ assert(0 == stat(archive_entry_pathname(ae), &st));
+ failure("st.st_mode=%o archive_entry_mode(ae)=%o",
+ st.st_mode, archive_entry_mode(ae));
+ assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK));
+ failure(msg);
+ assertEqualInt(st.st_size, sizeof(data));
+}
#endif
DEFINE_TEST(test_write_disk)
@@ -178,6 +233,20 @@ DEFINE_TEST(test_write_disk)
create_reg_file2(ae, "Test creating another regular file");
archive_entry_free(ae);
+ /* A regular file with a size restriction */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "file3");
+ archive_entry_set_mode(ae, S_IFREG | 0755);
+ create_reg_file3(ae, "Regular file with size restriction");
+ archive_entry_free(ae);
+
+ /* A regular file with an unspecified size */
+ assert((ae = archive_entry_new()) != NULL);
+ archive_entry_copy_pathname(ae, "file3");
+ archive_entry_set_mode(ae, S_IFREG | 0755);
+ create_reg_file4(ae, "Regular file with unspecified size");
+ archive_entry_free(ae);
+
/* A regular file over an existing file */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "file");
OpenPOWER on IntegriCloud