From owner-p4-projects@FreeBSD.ORG Mon Aug 11 15:38:43 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 67FBB1065672; Mon, 11 Aug 2008 15:38:43 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2BBCE106566B for ; Mon, 11 Aug 2008 15:38:43 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 193408FC1C for ; Mon, 11 Aug 2008 15:38:43 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7BFcgXD030128 for ; Mon, 11 Aug 2008 15:38:42 GMT (envelope-from strauss@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7BFcgHc030126 for perforce@freebsd.org; Mon, 11 Aug 2008 15:38:42 GMT (envelope-from strauss@FreeBSD.org) Date: Mon, 11 Aug 2008 15:38:42 GMT Message-Id: <200808111538.m7BFcgHc030126@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to strauss@FreeBSD.org using -f From: Anselm Strauss To: Perforce Change Reviews Cc: Subject: PERFORCE change 147156 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2008 15:38:43 -0000 http://perforce.freebsd.org/chv.cgi?CH=147156 Change 147156 by strauss@strauss_marvelman on 2008/08/11 15:38:27 Added support for extra fields (mtime, atime, ctime, uid, gid), somehow format is still wrong, unzip does not recognize it Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#29 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#29 (text+ko) ==== @@ -43,8 +43,11 @@ #define ZIP_SIGNATURE_DATA_DESCRIPTOR 0x08074b50 #define ZIP_SIGNATURE_FILE_HEADER 0x02014b50 #define ZIP_SIGNATURE_CENTRAL_DIRECTORY_END 0x06054b50 +#define ZIP_SIGNATURE_EXTRA_TIMESTAMP 0x5455 +#define ZIP_SIGNATURE_EXTRA_UNIX 0x7855 #define ZIP_VERSION_EXTRACT 0x0014 /* ZIP version 2.0 is needed. */ -#define ZIP_VERSION_BY 0x0314 /* Made by UNIX, using ZIP version 2.0. */ +#define ZIP_VERSION_BY 0x0314 /* Made by UNIX, using ZIP version 2.0. */ +#define ZIP_FLAGS 0x04 /* Flagging bit 3 for using data descriptor. */ static ssize_t archive_write_zip_data(struct archive_write *, const void *buff, size_t s); static int archive_write_zip_finish(struct archive_write *); @@ -93,9 +96,24 @@ char uncompressed_size[4]; }; +struct zip_extra_data { + char time_id[2]; + char time_size[2]; + struct time_data { + char flag; + char data[4]; + } mtime, atime, ctime; + char unix_id[2]; + char unix_size[2]; + char unix_uid[2]; + char unix_gid[2]; +}; + struct zip_file_header_link { struct zip_file_header_link *next; struct archive_entry *entry; + char extra_length[2]; + struct zip_extra_data extra_data; off_t offset; uLong crc32; }; @@ -159,22 +177,25 @@ static int archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) { - /* TODO: Also handle non-regular file entries. */ - if (archive_entry_filetype(entry) != AE_IFREG) { - archive_set_error(&a->archive, EPERM, "Non-regular files are not yet supported."); - return ARCHIVE_FAILED; - }; - struct zip *zip; struct zip_local_file_header h; + struct zip_extra_data e; struct zip_data_descriptor *d; struct zip_file_header_link *l; const char *path; int ret; + int64_t size; + /* TODO: Also handle non-regular file entries. */ + if (archive_entry_filetype(entry) != AE_IFREG) { + archive_set_error(&a->archive, EPERM, "Non-regular files are not yet supported."); + return ARCHIVE_FAILED; + }; + zip = a->format_data; d = &zip->data_descriptor; path = archive_entry_pathname(entry); + size = archive_entry_size(entry); /* Append archive entry to the central directory data. * Storing in reverse order, for ease of coding. @@ -205,26 +226,47 @@ memset(&h, 0, sizeof(h)); zip_encode(ZIP_SIGNATURE_LOCAL_FILE_HEADER, &h.signature, sizeof(h.signature)); zip_encode(ZIP_VERSION_EXTRACT, &h.version, sizeof(h.version)); - zip_encode(0x4, &h.flags, sizeof(h.flags)); /* Flagging bit 3 for using data descriptor. */ + zip_encode(ZIP_FLAGS, &h.flags, sizeof(h.flags)); zip_encode(dos_time(archive_entry_mtime(entry)), &h.timedate, sizeof(h.timedate)); zip_encode(strlen(path), &h.filename_length, sizeof(h.filename_length)); + zip_encode(sizeof(e), &h.extra_length, sizeof(h.extra_length)); + + /* Formatting extra data. */ + zip_encode(sizeof(e), &h.extra_length, sizeof(h.extra_length)); + zip_encode(ZIP_SIGNATURE_EXTRA_TIMESTAMP, &e.time_id, sizeof(e.time_id)); + zip_encode(sizeof(e.atime) + sizeof(e.mtime) + sizeof(e.ctime), &e.time_size, sizeof(e.time_size)); + zip_encode(0x01, &e.mtime.flag, sizeof(e.mtime.flag)); + zip_encode(archive_entry_mtime(entry), &e.mtime.data, sizeof(e.mtime.data)); + zip_encode(0x02, &e.atime.flag, sizeof(e.atime.flag)); + zip_encode(archive_entry_atime(entry), &e.atime.data, sizeof(e.atime.data)); + zip_encode(0x04, &e.ctime.flag, sizeof(e.ctime.flag)); + zip_encode(archive_entry_ctime(entry), &e.ctime.data, sizeof(e.ctime.data)); + zip_encode(ZIP_SIGNATURE_EXTRA_UNIX, &e.unix_id, sizeof(e.unix_id)); + zip_encode(sizeof(e.unix_uid) + sizeof(e.unix_gid), &e.unix_size, sizeof(e.unix_size)); + zip_encode(archive_entry_uid(entry), &e.unix_uid, sizeof(e.unix_uid)); + zip_encode(archive_entry_gid(entry), &e.unix_gid, sizeof(e.unix_gid)); + l->extra_data = e; + l->extra_length[0] = h.extra_length[0]; + l->extra_length[1] = h.extra_length[1]; /* This will surely change when compression is implemented. */ - int64_t size = archive_entry_size(entry); zip_encode(size, &d->compressed_size, sizeof(d->compressed_size)); zip_encode(size, &d->uncompressed_size, sizeof(d->uncompressed_size)); ret = (a->compressor.write)(a, &h, sizeof(h)); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(h); ret = (a->compressor.write)(a, path, strlen(path)); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); + zip->written_bytes += strlen(path); - zip->written_bytes += strlen(path); + ret = (a->compressor.write)(a, &e, sizeof(e)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(e); return (ARCHIVE_OK); } @@ -296,6 +338,7 @@ zip_encode(ZIP_SIGNATURE_FILE_HEADER, &h.signature, sizeof(h.signature)); zip_encode(ZIP_VERSION_EXTRACT, &h.version_extract, sizeof(h.version_extract)); zip_encode(ZIP_VERSION_BY, &h.version_by, sizeof(h.version_by)); + zip_encode(ZIP_FLAGS, &h.flags, sizeof(h.flags)); entries = 0; offset_start = zip->written_bytes; @@ -309,20 +352,25 @@ zip_encode(size, &h.compressed_size, sizeof(h.compressed_size)); zip_encode(size, &h.uncompressed_size, sizeof(h.uncompressed_size)); zip_encode(strlen(path), &h.filename_length, sizeof(h.filename_length)); + h.extra_length[0] = l->extra_length[0]; + h.extra_length[1] = l->extra_length[1]; zip_encode(l->offset, &h.offset, sizeof(h.offset)); - /* Writing file header. */ ret = (a->compressor.write)(a, &h, sizeof(h)); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); zip->written_bytes += sizeof(h); - /* Writing filename. */ ret = (a->compressor.write)(a, path, strlen(path)); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); zip->written_bytes += strlen(path); + ret = (a->compressor.write)(a, &l->extra_data, sizeof(l->extra_data)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(l->extra_data); + l = l->next; entries++; }