]> granicus.if.org Git - php/commitdiff
make zip optional
authorGreg Beaver <cellog@php.net>
Sat, 12 Jan 2008 05:17:12 +0000 (05:17 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 12 Jan 2008 05:17:12 +0000 (05:17 +0000)
ext/phar/config.m4
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/phar_object.c
ext/phar/zip.c

index fb5c8ccc5739afc204a12ba4e86b6152a3578261..cc8c1270c7bbfd10b3c441681ece2cdd92f50be8 100644 (file)
@@ -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
index f04510a47acbe9f923b4e216b6768427b61e6f0f..be42e2d736222970f64c364442602009bdb763da 100644 (file)
@@ -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?"<br />":"\n");       
        PUTS("Phar fully realized by Gregory Beaver and Marcus Boerger.");
+       PUTS(!sapi_module.phpinfo_as_text?"<br />":"\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")
index e6870860d0cf3dc36c7923058b91bc9331ddc6e5..95b3d80e222f70d02dc50a4e8417162690947c76 100755 (executable)
@@ -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"
index e46198ae3f0209e39e60b09cbfb8abe8208b694b..aae4e82972b8e106b2d0a200f094e19c4d71604d 100755 (executable)
@@ -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;
index 0ba19aad9dc781478431fc1dbf68bf895892b798..9088cab1ded31bb742bded9580e09319329b427d 100644 (file)
@@ -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 */