mirror of
https://github.com/php/php-src.git
synced 2024-12-15 04:45:03 +08:00
add Phar->isWritable() for detecting whether a phar archive can be written to based on phar.readonly combined with actual file permissions
[DOC]
This commit is contained in:
parent
1c3097fcbe
commit
06df9bff83
@ -2094,6 +2094,28 @@ PHP_METHOD(Phar, isCompressed)
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ proto bool Phar::isWritable()
|
||||||
|
* Returns true if phar.readonly=0 or phar is a PharData AND the actual file is writable.
|
||||||
|
*/
|
||||||
|
PHP_METHOD(Phar, isWritable)
|
||||||
|
{
|
||||||
|
php_stream_statbuf ssb;
|
||||||
|
PHAR_ARCHIVE_OBJECT();
|
||||||
|
|
||||||
|
if (!phar_obj->arc.archive->is_writeable) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
if (SUCCESS != php_stream_stat_path(phar_obj->arc.archive->fname, &ssb)) {
|
||||||
|
if (phar_obj->arc.archive->is_brandnew) {
|
||||||
|
/* assume it works if the file doesn't exist yet */
|
||||||
|
RETURN_TRUE;
|
||||||
|
}
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
RETURN_BOOL((ssb.sb.st_mode & (S_IWOTH | S_IWGRP | S_IWUSR)) != 0);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ proto bool Phar::delete(string entry)
|
/* {{{ proto bool Phar::delete(string entry)
|
||||||
* Deletes a named file within the archive.
|
* Deletes a named file within the archive.
|
||||||
*/
|
*/
|
||||||
@ -3925,6 +3947,7 @@ zend_function_entry php_archive_methods[] = {
|
|||||||
PHP_ME(Phar, hasMetadata, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(Phar, hasMetadata, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(Phar, isBuffering, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(Phar, isBuffering, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(Phar, isCompressed, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(Phar, isCompressed, NULL, ZEND_ACC_PUBLIC)
|
||||||
|
PHP_ME(Phar, isWritable, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(Phar, isPhar, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(Phar, isPhar, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(Phar, isTar, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(Phar, isTar, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(Phar, isZip, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(Phar, isZip, NULL, ZEND_ACC_PUBLIC)
|
||||||
|
@ -8,6 +8,7 @@ phar.require_hash=0
|
|||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
|
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php';
|
||||||
|
$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
|
||||||
$pname = 'phar://hio';
|
$pname = 'phar://hio';
|
||||||
$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
|
$file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
|
||||||
|
|
||||||
@ -17,6 +18,9 @@ $files['dir/'] = '';
|
|||||||
$hasdir = 1;
|
$hasdir = 1;
|
||||||
include 'files/phar_test.inc';
|
include 'files/phar_test.inc';
|
||||||
$a = new Phar($fname);
|
$a = new Phar($fname);
|
||||||
|
$b = new PharData($fname2);
|
||||||
|
$b['test'] = 'hi';
|
||||||
|
|
||||||
var_dump($a['a.php']->isWritable());
|
var_dump($a['a.php']->isWritable());
|
||||||
var_dump($a['a.php']->isReadable());
|
var_dump($a['a.php']->isReadable());
|
||||||
$a['a.php']->chmod(000);
|
$a['a.php']->chmod(000);
|
||||||
@ -34,10 +38,26 @@ clearstatcache();
|
|||||||
var_dump($a['a.php']->isWritable());
|
var_dump($a['a.php']->isWritable());
|
||||||
var_dump($a['a.php']->isReadable());
|
var_dump($a['a.php']->isReadable());
|
||||||
?>
|
?>
|
||||||
|
archive
|
||||||
|
<?php
|
||||||
|
ini_set('phar.readonly',0);
|
||||||
|
clearstatcache();
|
||||||
|
var_dump($a->isWritable());
|
||||||
|
var_dump($b->isWritable());
|
||||||
|
ini_set('phar.readonly',1);
|
||||||
|
clearstatcache();
|
||||||
|
var_dump($a->isWritable());
|
||||||
|
var_dump($b->isWritable());
|
||||||
|
chmod($fname2, 000);
|
||||||
|
clearstatcache();
|
||||||
|
var_dump($a->isWritable());
|
||||||
|
var_dump($b->isWritable());
|
||||||
|
?>
|
||||||
===DONE===
|
===DONE===
|
||||||
--CLEAN--
|
--CLEAN--
|
||||||
<?php
|
<?php
|
||||||
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
|
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php');
|
||||||
|
unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
bool(true)
|
bool(true)
|
||||||
@ -50,4 +70,11 @@ bool(false)
|
|||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
archive
|
||||||
|
bool(true)
|
||||||
|
bool(true)
|
||||||
|
bool(false)
|
||||||
|
bool(true)
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
===DONE===
|
===DONE===
|
||||||
|
Loading…
Reference in New Issue
Block a user