]> granicus.if.org Git - php/commitdiff
fix errors found in delMetaData(), add get/delMetaData() to MetaData read test
authorGreg Beaver <cellog@php.net>
Sun, 25 Nov 2007 05:04:40 +0000 (05:04 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 25 Nov 2007 05:04:40 +0000 (05:04 +0000)
ext/phar/config.m4
ext/phar/config.w32
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/phar_object.c
ext/phar/tests/phar_metadata_read.phpt

index e80cf38e8de72a3c7a760e1f68e62c7393ce11d4..75c26eae52c33c9f00891fcba29733541e98c036 100644 (file)
@@ -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)
index 035bcfefdead3ec4d65d1b040f5e84578ec3402a..d393a1a06c5bd95d6518cf3f9c3d41f1e0a055e1 100644 (file)
@@ -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);
index 442c0479502582c52efb6ab1d134ccfccdb3aa98..6ddb4c4cdd0c5de38f54e2cca2bf08c9f7907a92 100644 (file)
@@ -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
index 3a482a07dce05c29113822917e17efeb9d808938..0c4e85c436c58df0917f2a507223128f349c763d 100755 (executable)
@@ -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)
index 0d6fd132b944f94cb6d57507a32260563ce59aa4..7816dc3e4dcf7b8b0679f5c13790cfa08fc1de9e 100755 (executable)
@@ -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");
        }
index eca251428479ffdabc757684dc12c00dead294fb..cf41b6adf7e069d7dea5fca9378ed92b1635de0a 100644 (file)
@@ -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"