From: Greg Beaver Date: Tue, 6 May 2008 21:46:26 +0000 (+0000) Subject: fix zip metadata for archive/fix perms for file in zip/all.phpt test X-Git-Tag: RELEASE_2_0_0b1~77 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96d4c2b62fc8cf0c44e0d508d317da7b805a7519;p=php fix zip metadata for archive/fix perms for file in zip/all.phpt test --- diff --git a/ext/phar/tests/zip/all.phpt b/ext/phar/tests/zip/all.phpt index 55f1e9c0a8..84bbfc36be 100644 --- a/ext/phar/tests/zip/all.phpt +++ b/ext/phar/tests/zip/all.phpt @@ -53,7 +53,7 @@ string(3) "hi3" bool(false) bool(true) bool(true) -string(4) "0444" +string(6) "100444" string(32) " " string(4) "hime" diff --git a/ext/phar/zip.c b/ext/phar/zip.c index e8b46e4ce5..888d135f51 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -633,6 +633,7 @@ continue_dir: /* set file metadata */ if (entry->metadata) { php_serialize_data_t metadata_hash; + if (entry->metadata_str.c) { smart_str_free(&entry->metadata_str); } @@ -958,7 +959,6 @@ nostub: /* save zip */ eocd.cdir_size = php_stream_tell(pass.centralfp); eocd.cdir_offset = php_stream_tell(pass.filefp); - /* implement metadata here */ php_stream_seek(pass.centralfp, 0, SEEK_SET); if (eocd.cdir_size != php_stream_copy_to_stream(pass.centralfp, pass.filefp, PHP_STREAM_COPY_ALL)) { php_stream_close(pass.filefp); @@ -972,21 +972,23 @@ nostub: return EOF; } php_stream_close(pass.centralfp); - if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) { - php_stream_close(pass.filefp); - if (error) { - spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname); - } - if (closeoldfile) { - php_stream_close(oldfile); - } - return EOF; - } if (phar->metadata) { /* set phar metadata */ PHP_VAR_SERIALIZE_INIT(metadata_hash); php_var_serialize(&main_metadata_str, &phar->metadata, &metadata_hash TSRMLS_CC); PHP_VAR_SERIALIZE_DESTROY(metadata_hash); + eocd.comment_len = PHAR_SET_16(main_metadata_str.len); + if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) { + php_stream_close(pass.filefp); + if (error) { + spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname); + } + if (closeoldfile) { + php_stream_close(oldfile); + } + smart_str_free(&main_metadata_str); + return EOF; + } if (main_metadata_str.len != php_stream_write(pass.filefp, main_metadata_str.c, main_metadata_str.len)) { php_stream_close(pass.filefp); if (error) { @@ -995,9 +997,21 @@ nostub: if (closeoldfile) { php_stream_close(oldfile); } + smart_str_free(&main_metadata_str); return EOF; } smart_str_free(&main_metadata_str); + } else { + if (sizeof(eocd) != php_stream_write(pass.filefp, (char *)&eocd, sizeof(eocd))) { + php_stream_close(pass.filefp); + if (error) { + spprintf(error, 4096, "phar zip flush of \"%s\" failed: unable to write end of central-directory", phar->fname); + } + if (closeoldfile) { + php_stream_close(oldfile); + } + return EOF; + } } if (phar->fp && pass.free_fp) { php_stream_close(phar->fp);