]> granicus.if.org Git - php/commitdiff
experimental support for optional bz2 extension - should make windows users a whole...
authorGreg Beaver <cellog@php.net>
Sat, 24 Nov 2007 04:06:44 +0000 (04:06 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 24 Nov 2007 04:06:44 +0000 (04:06 +0000)
ext/phar/config.m4
ext/phar/phar.c
ext/phar/phar_object.c

index 4e31e7126b82691452ffa8420398602ac5deff38..d5a189a32037021f4af2209165c709bcb475cca0 100644 (file)
@@ -7,7 +7,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, bz2, true)
+  PHP_ADD_EXTENSION_DEP(phar, bz2, false)
   PHP_ADD_EXTENSION_DEP(phar, spl, false)
   PHP_ADD_MAKEFILE_FRAGMENT
 fi
index 1516ad0aa67a086c2459cc965c38b3a455c4d649..54953651cb68a61da0e96b644de03137f7dfa1fe 100644 (file)
@@ -1250,6 +1250,10 @@ 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"))) {
+                               MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\"");
+                       }
 #endif
                        break;
                default:
@@ -3801,10 +3805,16 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */
 #else
                "disabled");
 #endif
-       php_info_print_table_row(2, "bzip2 compression", 
 #if HAVE_BZ2
-               "enabled");
+        if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
+               php_info_print_table_row(2, "bzip2 compression", 
+                       "disabled");
+       } else {
+               php_info_print_table_row(2, "bzip2 compression", 
+                       "enabled");
+       }
 #else
+       php_info_print_table_row(2, "bzip2 compression", 
                "disabled");
 #endif
        php_info_print_table_end();
@@ -3826,7 +3836,7 @@ static zend_module_dep phar_deps[] = {
        ZEND_MOD_REQUIRED("zlib")
 #endif
 #if HAVE_BZ2
-       ZEND_MOD_REQUIRED("bz2")
+       ZEND_MOD_OPTIONAL("bz2")
 #endif
 #if HAVE_SPL
        ZEND_MOD_REQUIRED("spl")
index 5cd713db16a18c2b6665d6b3eccbf9c536e104aa..7ef53ad000c602bda88b15f16fce9efd9888299c 100755 (executable)
@@ -151,14 +151,22 @@ PHP_METHOD(Phar, canCompress)
 
        case PHAR_ENT_COMPRESSED_BZ2:
 #if HAVE_BZ2
+        if (zend_hash_exists(&module_registry, "bz2", sizeof("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) {
                RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
 #else
                RETURN_FALSE;
 #endif
@@ -588,7 +596,9 @@ PHP_METHOD(Phar, getSupportedCompression)
        add_next_index_stringl(return_value, "GZ", 2, 1);
 #endif
 #if !HAVE_BZ2
-       add_next_index_stringl(return_value, "BZIP2", 5, 1);
+        if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
+               add_next_index_stringl(return_value, "BZIP2", 5, 1);
+       }
 #endif
 }
 /* }}} */
@@ -658,8 +668,10 @@ static int phar_test_compression(void *pDest, void *argument TSRMLS_DC) /* {{{ *
                return ZEND_HASH_APPLY_KEEP;
        }
 #if !HAVE_BZ2
-       if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
-               *(int *) argument = 0;
+        if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
+               if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
+                       *(int *) argument = 0;
+               }
        }
 #endif
 #if !HAVE_ZLIB
@@ -735,6 +747,10 @@ PHP_METHOD(Phar, compressAllFilesBZIP2)
                        "Phar is readonly, cannot change compression");
        }
 #if HAVE_BZ2
+        if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
+               zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+                       "Cannot compress with Bzip2 compression, bz2 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 Bzip2, some are compressed as gzip and cannot be uncompressed");
@@ -1419,6 +1435,10 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2)
        char *error;
        PHAR_ENTRY_OBJECT();
 
+        if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
+               zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+                       "Cannot compress with Bzip2 compression, bz2 extension is not enabled");
+       }
        if (entry_obj->ent.entry->is_dir) {
                zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
                        "Phar entry is a directory, cannot set compression"); \
@@ -1490,6 +1510,11 @@ PHP_METHOD(PharFileInfo, setUncompressed)
                zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
                        "Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled");
        }
+#else
+        if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
+               zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+                       "Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled");
+       }
 #endif
        if (!entry_obj->ent.entry->fp) {
                fname_len = spprintf(&fname, 0, "phar://%s/%s", entry_obj->ent.entry->phar->fname, entry_obj->ent.entry->filename);