cvs: pecl /phar phar.c /phar/tests phar_oo_iswriteable.phpt
| From: | Greg Beaver | Date: | Thu, 10 Apr 2008 03:12:07 +0000 |
| Subject: | cvs: pecl /phar phar.c /phar/tests phar_oo_iswriteable.phpt | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-10330@lists.php.net to get a copy of this message | ||
cellog Thu Apr 10 03:12:07 2008 UTC
Added files:
/pecl/phar/tests phar_oo_iswriteable.phpt
Modified files:
/pecl/phar phar.c
Log:
make built-in SplFileInfo->isWriteable() work for PharFileInfo as well, by ensuring
phar->is_writeable is set/reset when phar.readonly is changed
http://cvs.php.net/viewvc.cgi/pecl/phar/phar.c?r1=1.327&r2=1.328&diff_format=u
Index: pecl/phar/phar.c
diff -u pecl/phar/phar.c:1.327 pecl/phar/phar.c:1.328
--- pecl/phar/phar.c:1.327 Thu Mar 27 12:54:22 2008
+++ pecl/phar/phar.c Thu Apr 10 03:12:07 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: phar.c,v 1.327 2008/03/27 12:54:22 helly Exp $ */
+/* $Id: phar.c,v 1.328 2008/04/10 03:12:07 cellog Exp $ */
#define PHAR_MAIN 1
#include "phar_internal.h"
@@ -26,6 +26,21 @@
ZEND_DECLARE_MODULE_GLOBALS(phar)
+/**
+ * set's phar->is_writeable based on the current INI value
+ */
+static int phar_set_writeable_bit(void *pDest, void *argument TSRMLS_DC) /* {{{ */
+{
+ zend_bool keep = *(zend_bool *)argument;
+ phar_archive_data *phar = *(phar_archive_data **)pDest;
+
+ if (!phar->is_data) {
+ phar->is_writeable = !keep;
+ }
+ return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+
/* if the original value is 0 (disabled), then allow setting/unsetting at will
otherwise, only allow 1 (enabled), and error on disabling */
ZEND_INI_MH(phar_ini_modify_handler) /* {{{ */
@@ -63,7 +78,10 @@
}
if (entry->name_length == 14) {
- PHAR_G(readonly) = ini;
+ PHAR_G(readonly) = ini;
+ if (PHAR_GLOBALS->request_init && PHAR_GLOBALS->phar_fname_map.arBuckets) {
+ zend_hash_apply_with_argument(&(PHAR_GLOBALS->phar_fname_map), phar_set_writeable_bit,
(void *)&ini TSRMLS_CC);
+ }
} else {
PHAR_G(require_hash) = ini;
}
@@ -2837,7 +2855,7 @@
php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION);
php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION);
- php_info_print_table_row(2, "CVS revision", "$Revision: 1.327 $");
+ php_info_print_table_row(2, "CVS revision", "$Revision: 1.328 $");
php_info_print_table_row(2, "Phar-based phar archives", "enabled");
php_info_print_table_row(2, "Tar-based phar archives", "enabled");
php_info_print_table_row(2, "ZIP-based phar archives", "enabled");
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_oo_iswriteable.phpt?view=markup&rev=1.1
Index: pecl/phar/tests/phar_oo_iswriteable.phpt
+++ pecl/phar/tests/phar_oo_iswriteable.phpt
--TEST--
Phar::isWriteable
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--INI--
phar.readonly=0
phar.require_hash=0
--FILE--
<?php
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') .
'.1.phar.php';
$pname = 'phar://hio';
$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER();
?>';
$files = array();
$files['a.php'] = '<?php echo "This is a\n"; include
"'.$pname.'/b.php"; ?>';
$files['dir/'] = '';
$hasdir = 1;
include 'files/phar_test.inc';
$a = new Phar($fname);
var_dump($a['a.php']->isWritable());
var_dump($a['a.php']->isReadable());
$a['a.php']->chmod(000);
var_dump($a['a.php']->isWritable());
var_dump($a['a.php']->isReadable());
$a['a.php']->chmod(0666);
var_dump($a['a.php']->isWritable());
var_dump($a['a.php']->isReadable());
ini_set('phar.readonly',1);
clearstatcache();
var_dump($a['a.php']->isWritable());
var_dump($a['a.php']->isReadable());
ini_set('phar.readonly',0);
clearstatcache();
var_dump($a['a.php']->isWritable());
var_dump($a['a.php']->isReadable());
?>
===DONE===
--CLEAN--
<?php
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') .
'.1.phar.php');
?>
--EXPECT--
bool(true)
bool(true)
bool(false)
bool(false)
bool(true)
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)
===DONE===