From: Greg Beaver Date: Sat, 24 Nov 2007 04:06:44 +0000 (+0000) Subject: experimental support for optional bz2 extension - should make windows users a whole... X-Git-Tag: RELEASE_2_0_0a1~1292 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a72251be6e2552d5e74d49a8705dcc1fc31304ab;p=php experimental support for optional bz2 extension - should make windows users a whole lot happier --- diff --git a/ext/phar/config.m4 b/ext/phar/config.m4 index 4e31e7126b..d5a189a320 100644 --- a/ext/phar/config.m4 +++ b/ext/phar/config.m4 @@ -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 diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 1516ad0aa6..54953651cb 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -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") diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 5cd713db16..7ef53ad000 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -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);