From: Greg Beaver Date: Sun, 25 Nov 2007 05:04:40 +0000 (+0000) Subject: fix errors found in delMetaData(), add get/delMetaData() to MetaData read test X-Git-Tag: RELEASE_2_0_0a1~1280 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bcb68a4e805e4dc62f0758ff88962e3bfedc086;p=php fix errors found in delMetaData(), add get/delMetaData() to MetaData read test --- diff --git a/ext/phar/config.m4 b/ext/phar/config.m4 index e80cf38e8d..75c26eae52 100644 --- a/ext/phar/config.m4 +++ b/ext/phar/config.m4 @@ -6,7 +6,7 @@ PHP_ARG_ENABLE(phar, for phar support/phar zlib support, if test "$PHP_PHAR" != "no"; then PHP_NEW_EXTENSION(phar, phar.c phar_object.c phar_path_check.c, $ext_shared) - PHP_ADD_EXTENSION_DEP(phar, zlib, true) + PHP_ADD_EXTENSION_DEP(phar, zlib, false) PHP_ADD_EXTENSION_DEP(phar, bz2, false) PHP_ADD_EXTENSION_DEP(phar, spl, false) PHP_ADD_EXTENSION_DEP(phar, gnupg, false) diff --git a/ext/phar/config.w32 b/ext/phar/config.w32 index 035bcfefde..d393a1a06c 100644 --- a/ext/phar/config.w32 +++ b/ext/phar/config.w32 @@ -5,7 +5,7 @@ ARG_ENABLE("phar", "enable phar support", "no"); if (PHP_PHAR != "no") { EXTENSION("phar", "phar.c phar_object.c phar_path_check.c"); - ADD_EXTENSION_DEP('phar', 'zlib', true); + ADD_EXTENSION_DEP('phar', 'zlib', false); ADD_EXTENSION_DEP('phar', 'bz2', false); ADD_EXTENSION_DEP('phar', 'spl', false); ADD_EXTENSION_DEP('phar', 'gnupg', false); diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 442c047950..6ddb4c4cdd 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1241,6 +1241,14 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int } efree(entry.filename); MAPPHAR_FAIL("zlib extension is required for gz compressed .phar file \"%s\""); +#else + if (!PHAR_G(has_zlib)) { + if (entry.metadata) { + zval_ptr_dtor(&entry.metadata); + } + efree(entry.filename); + MAPPHAR_FAIL("zlib extension is required for gz compressed .phar file \"%s\""); + } #endif break; case PHAR_ENT_COMPRESSED_BZ2: @@ -1251,7 +1259,11 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int efree(entry.filename); MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\""); #else - if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { + if (!PHAR_G(has_bz2)) { + if (entry.metadata) { + zval_ptr_dtor(&entry.metadata); + } + efree(entry.filename); MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\""); } #endif @@ -3750,6 +3762,9 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */ ZEND_INIT_MODULE_GLOBALS(phar, php_phar_init_globals_module, NULL); REGISTER_INI_ENTRIES(); + PHAR_G(has_gnupg) = zend_hash_exists(&module_registry, "gnupg", sizeof("gnupg")); + PHAR_G(has_bz2) = zend_hash_exists(&module_registry, "bz2", sizeof("bz2")); + PHAR_G(has_zlib) = zend_hash_exists(&module_registry, "zlib", sizeof("zlib")); phar_object_init(TSRMLS_C); return php_register_url_stream_wrapper("phar", &php_stream_phar_wrapper TSRMLS_CC); @@ -3799,14 +3814,20 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ php_info_print_table_row(2, "Phar EXT version", PHAR_EXT_VERSION_STR); php_info_print_table_row(2, "Phar API version", PHAR_API_VERSION_STR); php_info_print_table_row(2, "CVS revision", "$Revision$"); - php_info_print_table_row(2, "gzip compression", #if HAVE_ZLIB - "enabled"); + if (PHAR_G(has_zlib)) { + php_info_print_table_row(2, "gzip compression", + "enabled"); + } else { + php_info_print_table_row(2, "gzip compression", + "disabled"); + } #else + php_info_print_table_row(2, "gzip compression", "disabled"); #endif #if HAVE_BZ2 - if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { + if (PHAR_G(has_bz2)) { php_info_print_table_row(2, "bzip2 compression", "disabled"); } else { @@ -3818,7 +3839,7 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ "disabled"); #endif #if HAVE_GNUPGLIB - if (zend_hash_exists(&module_registry, "gnupg", sizeof("gnupg"))) { + if (PHAR_G(has_gnupg)) { php_info_print_table_row(2, "GPG signature", "enabled"); } else { @@ -3845,12 +3866,12 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ */ static zend_module_dep phar_deps[] = { #if HAVE_ZLIB - ZEND_MOD_REQUIRED("zlib") + ZEND_MOD_OPTIONAL("zlib") #endif #if HAVE_BZ2 ZEND_MOD_OPTIONAL("bz2") #endif -#if HAVE_GNUPG +#if HAVE_GNUPGLIB ZEND_MOD_OPTIONAL("gnupg") #endif #if HAVE_SPL diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index 3a482a07dc..0c4e85c436 100755 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -114,6 +114,9 @@ ZEND_BEGIN_MODULE_GLOBALS(phar) int require_hash; int request_done; int request_ends; + int has_bz2:1; + int has_gnupg:1; + int has_zlib:1; ZEND_END_MODULE_GLOBALS(phar) ZEND_EXTERN_MODULE_GLOBALS(phar) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 0d6fd132b9..7816dc3e4d 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -144,25 +144,29 @@ PHP_METHOD(Phar, canCompress) switch (method) { case PHAR_ENT_COMPRESSED_GZ: #if HAVE_ZLIB - RETURN_TRUE; + if (PHAR_G(has_zlib)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } #else RETURN_FALSE; #endif case PHAR_ENT_COMPRESSED_BZ2: #if HAVE_BZ2 - if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } + if (PHAR_G(has_bz2)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } #else RETURN_FALSE; #endif default: #if HAVE_ZLIB || HAVE_BZ2 - if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2")) || HAVE_ZLIB) { + if (PHAR_G(has_zlib) || PHAR_G(has_bz2)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -592,11 +596,13 @@ PHP_METHOD(Phar, getSupportedCompression) { array_init(return_value); -#if !HAVE_ZLIB - add_next_index_stringl(return_value, "GZ", 2, 1); +#if HAVE_ZLIB + if (PHAR_G(has_zlib)) { + add_next_index_stringl(return_value, "GZ", 2, 1); + } #endif -#if !HAVE_BZ2 - if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { +#if HAVE_BZ2 + if (PHAR_G(has_bz2)) { add_next_index_stringl(return_value, "BZIP2", 5, 1); } #endif @@ -668,7 +674,11 @@ static int phar_test_compression(void *pDest, void *argument TSRMLS_DC) /* {{{ * return ZEND_HASH_APPLY_KEEP; } #if !HAVE_BZ2 - if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { + if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) { + *(int *) argument = 0; + } +#else + if (!PHAR_G(has_bz2)) { if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) { *(int *) argument = 0; } @@ -678,6 +688,12 @@ static int phar_test_compression(void *pDest, void *argument TSRMLS_DC) /* {{{ * if (entry->flags & PHAR_ENT_COMPRESSED_GZ) { *(int *) argument = 0; } +#else + if (!PHAR_G(has_zlib)) { + if (entry->flags & PHAR_ENT_COMPRESSED_GZ) { + *(int *) argument = 0; + } + } #endif return ZEND_HASH_APPLY_KEEP; } @@ -713,6 +729,10 @@ PHP_METHOD(Phar, compressAllFilesGZ) "Phar is readonly, cannot change compression"); } #if HAVE_ZLIB + if (!PHAR_G(has_zlib)) { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, + "Cannot compress with Gzip compression, zlib extension is not enabled"); + } if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress all files as Gzip, some are compressed as bzip2 and cannot be uncompressed"); @@ -747,7 +767,7 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) "Phar is readonly, cannot change compression"); } #if HAVE_BZ2 - if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { + if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress with Bzip2 compression, bz2 extension is not enabled"); } @@ -1067,7 +1087,7 @@ PHP_METHOD(Phar, delMetadata) RETURN_TRUE; } } else { - RETURN_FALSE; + RETURN_TRUE; } } /* }}} */ @@ -1377,7 +1397,7 @@ PHP_METHOD(PharFileInfo, delMetadata) RETURN_TRUE; } } else { - RETURN_FALSE; + RETURN_TRUE; } } /* }}} */ @@ -1407,6 +1427,10 @@ PHP_METHOD(PharFileInfo, setCompressedGZ) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress deleted file"); } + if (!PHAR_G(has_zlib)) { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, + "Cannot compress with Gzip compression, zlib extension is not enabled"); + } entry_obj->ent.entry->old_flags = entry_obj->ent.entry->flags; entry_obj->ent.entry->flags &= ~PHAR_ENT_COMPRESSION_MASK; entry_obj->ent.entry->flags |= PHAR_ENT_COMPRESSED_GZ; @@ -1435,7 +1459,7 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2) char *error; PHAR_ENTRY_OBJECT(); - if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { + if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress with Bzip2 compression, bz2 extension is not enabled"); } @@ -1504,6 +1528,11 @@ PHP_METHOD(PharFileInfo, setUncompressed) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot uncompress Gzip-compressed file, zlib extension is not enabled"); } +#else + if (!PHAR_G(has_zlib)) { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, + "Cannot uncompress Gzip-compressed file, zlib extension is not enabled"); + } #endif #if !HAVE_BZ2 if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) { @@ -1511,7 +1540,7 @@ PHP_METHOD(PharFileInfo, setUncompressed) "Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled"); } #else - if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) { + if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled"); } diff --git a/ext/phar/tests/phar_metadata_read.phpt b/ext/phar/tests/phar_metadata_read.phpt index eca2514284..cf41b6adf7 100644 --- a/ext/phar/tests/phar_metadata_read.phpt +++ b/ext/phar/tests/phar_metadata_read.phpt @@ -23,8 +23,17 @@ foreach($files as $name => $cont) { } $phar = new Phar($fname); +var_dump($phar->hasMetaData()); +var_dump($phar->getMetaData()); +var_dump($phar->delMetaData()); +var_dump($phar->getMetaData()); +var_dump($phar->delMetaData()); var_dump($phar->getMetaData()); foreach($files as $name => $cont) { + echo " meta $name\n"; + var_dump($phar[$name]->hasMetadata()); + var_dump($phar[$name]->getMetadata()); + var_dump($phar[$name]->delMetadata()); var_dump($phar[$name]->getMetadata()); } @@ -42,21 +51,42 @@ string(1) "a" string(1) "b" string(1) "c" string(1) "d" +bool(true) string(8) "hi there" +bool(true) +NULL +bool(true) +NULL + meta a +bool(false) NULL +bool(true) NULL + meta b +bool(false) +NULL +bool(true) +NULL + meta c +bool(true) array(2) { [0]=> string(2) "hi" [1]=> string(5) "there" } +bool(true) +NULL + meta d +bool(true) array(2) { ["hi"]=> string(5) "there" ["foo"]=> string(3) "bar" } +bool(true) +NULL string(1) "a" string(1) "b" string(1) "c"