From 4df43510b957c330fe055a4718dfa86ad565e724 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sat, 12 Jan 2008 05:17:12 +0000 Subject: [PATCH] make zip optional --- ext/phar/config.m4 | 19 +------------------ ext/phar/phar.c | 12 +++++++++--- ext/phar/phar_internal.h | 1 + ext/phar/phar_object.c | 2 +- ext/phar/zip.c | 15 +++++++++++++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/ext/phar/config.m4 b/ext/phar/config.m4 index fb5c8ccc57..cc8c1270c7 100644 --- a/ext/phar/config.m4 +++ b/ext/phar/config.m4 @@ -12,25 +12,8 @@ if test "$PHP_PHAR" != "no"; then AC_MSG_CHECKING([for zip-based phar support]) if test "$PHP_PHAR_ZIP" != "yes"; then AC_MSG_RESULT([yes]) - PHP_PHAR_SOURCES="$PHP_PHAR_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \ - lib/zip_fread.c lib/zip_open.c lib/zip_source_filep.c \ - lib/zip_strerror.c lib/zip_close.c lib/zip_error_get.c \ - lib/zip_file_error_get.c lib/zip_free.c lib/zip_rename.c \ - lib/zip_source_free.c lib/zip_unchange_all.c lib/zip_delete.c \ - lib/zip_error_get_sys_type.c lib/zip_file_get_offset.c \ - lib/zip_get_name.c lib/zip_replace.c lib/zip_source_function.c \ - lib/zip_unchange.c lib/zip_dirent.c lib/zip_error_strerror.c \ - lib/zip_file_strerror.c lib/zip_get_num_files.c \ - lib/zip_set_name.c lib/zip_source_zip.c lib/zip_unchange_data.c \ - lib/zip_entry_free.c lib/zip_error_to_str.c lib/zip_fopen.c \ - lib/zip_name_locate.c lib/zip_source_buffer.c lib/zip_stat.c \ - lib/zip_entry_new.c lib/zip_err_str.c lib/zip_fopen_index.c \ - lib/zip_new.c lib/zip_source_file.c lib/zip_stat_index.c lib/zip_get_archive_comment.c \ - lib/zip_get_file_comment.c lib/zip_set_archive_comment.c lib/zip_set_file_comment.c \ - lib/zip_unchange_archive.c lib/zip_memdup.c lib/zip_stat_init.c lib/zip_add_dir.c \ - lib/zip_error_clear.c lib/zip_file_error_clear.c" AC_DEFINE(HAVE_PHAR_ZIP,1,[ ]) - PHP_ADD_EXTENSION_DEP(phar, zip, false) + PHP_ADD_EXTENSION_DEP(phar, zip, true) else AC_MSG_RESULT([no]) fi diff --git a/ext/phar/phar.c b/ext/phar/phar.c index f04510a47a..be42e2d736 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -3225,6 +3225,7 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */ phar_has_gnupg = zend_hash_exists(&module_registry, "gnupg", sizeof("gnupg")); phar_has_bz2 = zend_hash_exists(&module_registry, "bz2", sizeof("bz2")); phar_has_zlib = zend_hash_exists(&module_registry, "zlib", sizeof("zlib")); + phar_has_zip = zend_hash_exists(&module_registry, "zip", sizeof("zip")); phar_orig_compile_file = zend_compile_file; zend_compile_file = phar_compile_file; @@ -3305,7 +3306,11 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ php_info_print_table_row(2, "Phar-based phar archives", "enabled"); php_info_print_table_row(2, "Tar-based phar archives", "enabled"); #if HAVE_PHAR_ZIP - php_info_print_table_row(2, "ZIP-based phar archives", "enabled"); + if (phar_has_zip) { + php_info_print_table_row(2, "ZIP-based phar archives", "enabled"); + } else { + php_info_print_table_row(2, "ZIP-based phar archives", "disabled (install pecl/zip)"); + } #else php_info_print_table_row(2, "ZIP-based phar archives", "unavailable"); #endif @@ -3313,7 +3318,7 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ if (phar_has_zlib) { php_info_print_table_row(2, "gzip compression", "enabled"); } else { - php_info_print_table_row(2, "gzip compression", "disabled"); + php_info_print_table_row(2, "gzip compression", "disabled (install ext/zlib)"); } #else php_info_print_table_row(2, "gzip compression", "unavailable"); @@ -3342,6 +3347,7 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ PUTS("Phar based on pear/PHP_Archive, original concept by Davey Shafik."); PUTS(!sapi_module.phpinfo_as_text?"
":"\n"); PUTS("Phar fully realized by Gregory Beaver and Marcus Boerger."); + PUTS(!sapi_module.phpinfo_as_text?"
":"\n"); PUTS("Portions of tar implementation Copyright (c) 2003-2007 Tim Kientzle."); php_info_print_box_end(); @@ -3353,7 +3359,7 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ */ static zend_module_dep phar_deps[] = { #if HAVE_PHAR_ZIP - ZEND_MOD_REQUIRED_EX("zip", ">=", "1.8.11") + ZEND_MOD_OPTIONAL_EX("zip", ">=", "1.8.11") #endif #if HAVE_ZLIB ZEND_MOD_OPTIONAL("zlib") diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index e6870860d0..95b3d80e22 100755 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -173,6 +173,7 @@ ZEND_EXTERN_MODULE_GLOBALS(phar) int phar_has_bz2; int phar_has_gnupg; int phar_has_zlib; +int phar_has_zip; #ifdef ZTS # include "TSRM.h" diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index e46198ae3f..aae4e82972 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -2461,7 +2461,7 @@ PHP_METHOD(PharFileInfo, chmod) zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" in phar \"%s\", write operations are prohibited", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname); return; } -#if HAVE_ZIP +#if HAVE_PHAR_ZIP if (entry_obj->ent.entry->is_zip) { zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" in phar \"%s\", not supported for zip-based phars", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname); return; diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 0ba19aad9d..9088cab1de 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -57,6 +57,11 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph *error = NULL; } + if (!phar_has_zip) { + spprintf(error, 4096, "phar zip error: cannot open zip-based phar \"%s\", ext/zip is not enabled", fname); + return FAILURE; + } + zip = zip_open(fname, 0, &ziperror); if (!zip) { if (error) { @@ -230,7 +235,7 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph } return SUCCESS; #else - spprintf(error, 4096, "Error: Cannot open zip-based phar \"%s\"", fname); + spprintf(error, 4096, "phar zip error: Cannot open zip-based phar \"%s\", phar not compiled with zip enabled", fname); return FAILURE; #endif } @@ -255,6 +260,12 @@ int phar_open_or_create_zip(char *fname, int fname_len, char *alias, int alias_l return ret; } + if (!phar_has_zip) { + if (error) { + spprintf(error, 4096, "phar zip error: phar \"%s\" cannot be created as zip-based phar, zip-based phars are disabled (enable ext/zip)", fname); + } + return FAILURE; + } if (phar->is_brandnew) { int *errorp = NULL; phar->is_zip = 1; @@ -301,7 +312,7 @@ int phar_open_or_create_zip(char *fname, int fname_len, char *alias, int alias_l return FAILURE; #else if (error) { - spprintf(error, 4096, "phar zip error: phar \"%s\" cannot be created as zip-based phar, zip-based phars are disabled", fname); + spprintf(error, 4096, "phar zip error: phar \"%s\" cannot be created as zip-based phar, zip-based phars are disabled and cannot be enabled", fname); } return FAILURE; #endif /* #if HAVE_PHAR_ZIP */ -- 2.40.0