Browse Source

- Fix read/write mode handling

migration/RELEASE_1_0_0
Marcus Boerger 20 years ago
parent
commit
e1db72467c
  1. 17
      ext/phar/phar.c
  2. 2
      ext/phar/tests/create_new_phar_b.phpt
  3. 4
      ext/phar/tests/open_for_write_existing_b.phpt
  4. 4
      ext/phar/tests/open_for_write_existing_c.phpt
  5. 3
      ext/phar/tests/open_for_write_newfile_b.phpt
  6. 4
      ext/phar/tests/open_for_write_newfile_c.phpt
  7. 1
      ext/phar/tests/phar_oo_002.phpt

17
ext/phar/phar.c

@ -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);
}

2
ext/phar/tests/create_new_phar_b.phpt

@ -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

4
ext/phar/tests/open_for_write_existing_b.phpt

@ -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

4
ext/phar/tests/open_for_write_existing_c.phpt

@ -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

3
ext/phar/tests/open_for_write_newfile_b.phpt

@ -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

4
ext/phar/tests/open_for_write_newfile_c.phpt

@ -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

1
ext/phar/tests/phar_oo_002.phpt

@ -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

Loading…
Cancel
Save