From e0bc2b2be174c7e0bc367aa34aceb296e9691ff5 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Fri, 2 May 2008 04:44:39 +0000 Subject: [PATCH] update TODO, re-order methods to be alphabetical, tweak extractTo to set permissions and handle NULL for files # this also matches the docs I just committed :) --- ext/phar/TODO | 2 +- ext/phar/phar_object.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ext/phar/TODO b/ext/phar/TODO index 57c90881ca..d289671a1e 100644 --- a/ext/phar/TODO +++ b/ext/phar/TODO @@ -66,7 +66,7 @@ Version 2.0.0 X implement webPhar() rewrite as a callback that returns FALSE to deny access, or a string representing a file within the archive to access. If unknown, the callback should return the original request uri [Greg] - * rework filename detection so that alias is always checked first + X rework filename detection so that alias is always checked first [Greg] X make aliases containing '/' or '\' invalid [Greg] X implement manual mounting of external phar archives to locations inside a phar path, $phar->mount('/path/to/external.phar', 'internal/path'); diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 2ae7e34dd8..3bb16209dd 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -3527,10 +3527,18 @@ static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char * fullpath[dest_len] = '\0'; } if (FAILURE == php_stream_stat_path(fullpath, &ssb)) { - if (!php_stream_mkdir(fullpath, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL)) { - spprintf(error, 4096, "Cannot extract \"%s\", could not create directory \"%s\"", entry->filename, fullpath); - efree(fullpath); - return FAILURE; + if (entry->is_dir) { + if (!php_stream_mkdir(fullpath, entry->flags & PHAR_ENT_PERM_MASK, PHP_STREAM_MKDIR_RECURSIVE, NULL)) { + spprintf(error, 4096, "Cannot extract \"%s\", could not create directory \"%s\"", entry->filename, fullpath); + efree(fullpath); + return FAILURE; + } + } else { + if (!php_stream_mkdir(fullpath, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL)) { + spprintf(error, 4096, "Cannot extract \"%s\", could not create directory \"%s\"", entry->filename, fullpath); + efree(fullpath); + return FAILURE; + } } } if (slash) { @@ -3575,8 +3583,13 @@ static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char * php_stream_close(fp); return FAILURE; } - efree(fullpath); php_stream_close(fp); + if (-1 == VCWD_CHMOD(fullpath, entry->flags & PHAR_ENT_PERM_MASK)) { + spprintf(error, 4096, "Cannot extract \"%s\" to \"%s\", setting file permissions failed", entry->filename, fullpath); + efree(fullpath); + return FAILURE; + } + efree(fullpath); return SUCCESS; } @@ -3628,6 +3641,8 @@ PHP_METHOD(Phar, extractTo) if (zval_files) { switch (Z_TYPE_P(zval_files)) { + case IS_NULL: + goto all_files; case IS_STRING: filename = Z_STRVAL_P(zval_files); filename_len = Z_STRLEN_P(zval_files); @@ -3679,6 +3694,8 @@ PHP_METHOD(Phar, extractTo) } } else { phar_archive_data *phar = phar_obj->arc.archive; + +all_files: /* Extract all files */ if (!zend_hash_num_elements(&(phar->manifest))) { RETURN_TRUE; @@ -4480,18 +4497,18 @@ zend_function_entry php_entry_methods[] = { PHP_ME(PharFileInfo, __construct, arginfo_entry___construct, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, __destruct, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, chmod, arginfo_entry_chmod, ZEND_ACC_PUBLIC) + PHP_ME(PharFileInfo, compress, arginfo_phar_comp, ZEND_ACC_PUBLIC) + PHP_ME(PharFileInfo, decompress, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, delMetadata, NULL, ZEND_ACC_PUBLIC) - PHP_ME(PharFileInfo, getContent, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, getCompressedSize, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, getCRC32, NULL, ZEND_ACC_PUBLIC) + PHP_ME(PharFileInfo, getContent, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, getMetadata, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, getPharFlags, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, hasMetadata, NULL, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, isCompressed, arginfo_phar_compo, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, isCRCChecked, NULL, ZEND_ACC_PUBLIC) - PHP_ME(PharFileInfo, compress, arginfo_phar_comp, ZEND_ACC_PUBLIC) PHP_ME(PharFileInfo, setMetadata, arginfo_phar_setMetadata, ZEND_ACC_PUBLIC) - PHP_ME(PharFileInfo, decompress, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; #endif /* HAVE_SPL */ -- 2.40.0