Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Jul 2008 20:46:20 GMT
From:      Anselm Strauss <strauss@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 146346 for review
Message-ID:  <200807312046.m6VKkKc1042376@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=146346

Change 146346 by strauss@strauss_marvelman on 2008/07/31 20:45:35

	Added CRC32 in ZIP writer

Affected files ...

.. //depot/projects/soc2008/strauss_libarchive/TODO#13 edit
.. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#23 edit
.. //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#5 edit

Differences ...

==== //depot/projects/soc2008/strauss_libarchive/TODO#13 (text+ko) ====

@@ -1,7 +1,6 @@
 To Be Done
 ==========
 
-- Exception handling in ZIP writer, archive error setting
 - Update ZIP writer in docs
 - About the keywords: of course they always change when integrating ...
 - Not all P4 keywords do expand (tested on OS X and FreeBSD)
@@ -10,6 +9,7 @@
 Already Done
 ============
 
+- Exception handling in ZIP writer, archive error setting
 - Free archive entry clones in ZIP writer
 - Integrate Libarchive 2.5.5
 - How to enable '-Wall' in gcc when calling make? -> Use 'make CFLAGS="-Wall" ...'

==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#23 (text+ko) ====

@@ -32,6 +32,7 @@
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
+#include <zlib.h>
 
 #define ZIP_SIGNATURE_LOCAL_FILE_HEADER 0x04034b50
 #define ZIP_SIGNATURE_DATA_DESCRIPTOR 0x08074b50
@@ -93,6 +94,7 @@
 	struct zip_file_header_link *next;
 	struct archive_entry *entry;
 	off_t offset;
+	uLong crc32;
 };
 
 struct zip {
@@ -180,6 +182,7 @@
 		return (ARCHIVE_FATAL);
 	}
 	l->entry = archive_entry_clone(entry);
+	l->crc32 = crc32(0, NULL, 0);
 	l->next = zip->central_directory;
 	zip->central_directory = l;
 	
@@ -230,17 +233,17 @@
 {
 	int ret;
 	struct zip *zip = a->format_data;
+	struct zip_file_header_link *l = zip->central_directory;
 	
 	ret = (a->compressor.write)(a, buff, s);
 	if (ret >= 0) {
 		zip->written_bytes += s;
-		return (s);
+		l->crc32 = crc32(l->crc32, buff, s);
+		return s;
 	} else {
 		archive_set_error(&a->archive, EIO, "Error while writing ZIP data");
 		return (ret);
 	}
-		
-	/* TODO: Compute data descriptor CRC. */
 }
 
 static int
@@ -251,7 +254,10 @@
 	int ret;
 	struct zip *zip = a->format_data;
 	struct zip_data_descriptor *d = &zip->data_descriptor;
+	struct zip_file_header_link *l = zip->central_directory;
 	
+	zip_encode(l->crc32, &d->crc32, sizeof(d->crc32));
+	
 	ret = (a->compressor.write)(a, d, sizeof(*d));
 	if (ret != ARCHIVE_OK) {
 		archive_set_error(&a->archive, EIO, "Can't write data descriptor");
@@ -304,6 +310,7 @@
 		zip_encode(size, &h.uncompressed_size, sizeof(h.uncompressed_size));
 		zip_encode(strlen(path), &h.filename_length, sizeof(h.filename_length));
 		zip_encode(l->offset, &h.offset, sizeof(h.offset));
+		zip_encode(l->crc32, &h.crc32, sizeof(h.crc32));
 		
 		/* Writing file header. */
 		ret = (a->compressor.write)(a, &h, sizeof(h));

==== //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#5 (text+ko) ====

@@ -12,6 +12,7 @@
 {
 	struct archive *a;
 	struct archive_entry *entry;
+	char data[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
 	char buff[100000];
 	const char *p, *q, *buffend;
 	size_t used;
@@ -37,8 +38,10 @@
 	archive_entry_set_ino(entry, 89);
 	archive_entry_set_nlink(entry, 1);
 	assertEqualIntA(a, 0, archive_write_header(a, entry));
-	assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10));
+	assertEqualIntA(a, 10, archive_write_data(a, data, sizeof(data)));
 	archive_entry_free(entry);
+	
+	/* TODO: Also test non-regular file and directory entries. */
 
 	/* Close out the archive . */
 	assertA(0 == archive_write_close(a));
@@ -77,7 +80,7 @@
 	/* assertEqualInt(i2(p + 10), XXXX); */ /* Compression method */
 	/* assertEqualInt(i2(p + 12), XXXX); */ /* File time */
 	/* assertEqualInt(i2(p + 14), XXXX); */ /* File date */
-	/* assertEqualInt(i4(p + 16), XXXX); */ /* CRC-32 */
+	assertEqualInt(i4(p + 16), crc32(0, &data, sizeof(data))); /* CRC-32 */
 	/* assertEqualInt(i4(p + 20), XXXX); */ /* Compressed size */
 	/* assertEqualInt(i4(p + 24), XXXX); */ /* Uncompressed size */
 	/* assertEqualInt(i2(p + 28), XXXX); */ /* Filename length */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807312046.m6VKkKc1042376>