]> granicus.if.org Git - php/commitdiff
- Fix read/write mode handling
authorMarcus Boerger <helly@php.net>
Sun, 28 Jan 2007 10:32:45 +0000 (10:32 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 28 Jan 2007 10:32:45 +0000 (10:32 +0000)
ext/phar/phar.c
ext/phar/tests/create_new_phar_b.phpt
ext/phar/tests/open_for_write_existing_b.phpt
ext/phar/tests/open_for_write_existing_c.phpt
ext/phar/tests/open_for_write_newfile_b.phpt
ext/phar/tests/open_for_write_newfile_c.phpt
ext/phar/tests/phar_oo_002.phpt

index ef6843639d5287959ed4e4a25b5cae015536b35b..9b495172373ea74c26d56b5fad208f5cea391e58 100644 (file)
@@ -912,7 +912,9 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al
        }
 
        if (phar_open_loaded(fname, fname_len, alias, alias_len, options, pphar TSRMLS_CC) == SUCCESS) {
-               (*pphar)->is_writeable = 1;
+               if (!PHAR_G(readonly)) {
+                       (*pphar)->is_writeable = 1;
+               }
                return SUCCESS;
        }
 
@@ -926,10 +928,12 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al
                return FAILURE;
        }
 
-       fp = php_stream_open_wrapper(fname, "r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL);
+       fp = php_stream_open_wrapper(fname, PHAR_G(readonly)?"rb":"r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL);
 
        if (fp && phar_open_fp(fp, fname, fname_len, alias, alias_len, options, pphar TSRMLS_CC) == SUCCESS) {
-               (*pphar)->is_writeable = 1;
+               if (!PHAR_G(readonly)) {
+                       (*pphar)->is_writeable = 1;
+               }
                return SUCCESS;
        }
 
@@ -1142,6 +1146,11 @@ static php_url* phar_open_url(php_stream_wrapper *wrapper, char *filename, char
                }
 #endif
                if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) {
+                       if (PHAR_G(readonly)) {
+                               php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting");
+                               php_url_free(resource);
+                               return NULL;
+                       }
                        if (phar_open_or_create_filename(resource->host, arch_len, NULL, 0, options, NULL TSRMLS_CC) == FAILURE)
                        {
                                php_url_free(resource);
@@ -2232,7 +2241,7 @@ static void phar_dostat(phar_archive_data *phar, phar_entry_info *data, php_stre
                ssb->sb.st_ctime = phar->max_timestamp;
 #endif
        }
-       if (PHAR_G(readonly)) {
+       if (!phar->is_writeable) {
                ssb->sb.st_mode = (ssb->sb.st_mode & 0555) | (ssb->sb.st_mode & ~0777);
        }
 
index 9cf86fc1778be31960b3151f373e29aaf3114aa1..4f0601be10093262d61b172a2438c09d9044592d 100755 (executable)
@@ -18,7 +18,7 @@ include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.pha
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
 
-Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d
+Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d
 
 Warning: include(%screate_new_phar_b.phar.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d
 
index fbfce79c419254ebdd96dbb045afbf3d8138b3e6..a4f4d03092562cad19ada2a700f52d390c0b50e3 100755 (executable)
@@ -32,8 +32,8 @@ include $pname . '/b/c.php';
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
-Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: file "%sopen_for_write_existing_b.phar.php" cannot opened for writing, disabled by ini setting
-phar error: file "b/c.php" could not be created in phar "%sopen_for_write_existing_b.phar.php" in %sopen_for_write_existing_b.php on line %d
+
+Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d
 
 Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d
 
index 1733cea584a460de347551e8e7d00cb9cc8c86ce..b7a61c7b0b71b8a856a0058a494c56a39afddca6 100755 (executable)
@@ -26,8 +26,8 @@ include $pname . '/b/c.php';
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
-Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: file "%sopen_for_write_existing_c.phar.php" cannot opened for writing, disabled by ini setting
-phar error: file "b/c.php" could not be created in phar "%sopen_for_write_existing_c.phar.php" in %sopen_for_write_existing_c.php on line %d
+
+Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d
 
 Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d
 
index b62158201aa77f8f0e397de8fd1894cc866189ba..3ee7b70947f62b65a398f00cb8ebb25b7a7069ab 100755 (executable)
@@ -35,8 +35,7 @@ include $pname . '/b/new.php';
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
 
-Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: file "%sopen_for_write_newfile_b.phar.php" cannot opened for writing, disabled by ini setting
-phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line %d
+Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d
 
 Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d
 
index c4242bdb2e7b1168c2e6f34fb7f8bdf5a5eaf8c2..ce0562b48cba4310caab7cb66644262f0eab05d5 100755 (executable)
@@ -28,8 +28,8 @@ include $pname . '/b/new.php';
 --CLEAN--
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
 --EXPECTF--
-Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: file "%sopen_for_write_newfile_c.phar.php" cannot opened for writing, disabled by ini setting
-phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_c.phar.php" in %sopen_for_write_newfile_c.php on line %d
+
+Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d
 
 Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d
 
index d2769b034b0e02fce2b6649c97ba2d8a4e985ec1..080df2c61aa08c8aadc3ce2c179c73001fce2714 100755 (executable)
@@ -4,6 +4,7 @@ Phar object: iterator & entries
 <?php if (!extension_loaded("phar")) print "skip"; ?>
 <?php if (!extension_loaded("spl")) print "skip SPL not available"; ?>
 --INI--
+phar.readonly=1
 phar.require_hash=0
 --FILE--
 <?php