diff options
author | Greg Beaver <cellog@php.net> | 2008-03-24 03:01:31 +0000 |
---|---|---|
committer | Greg Beaver <cellog@php.net> | 2008-03-24 03:01:31 +0000 |
commit | 2e9fca4f0bc52bb929f7cc0bb26cf9e7f019c953 (patch) | |
tree | 2aefec783d1d3c74d93afabd22985417d9f060fc | |
parent | b4b890cb8f74ccb1728712b675fc2099a789da82 (diff) | |
download | php-git-2e9fca4f0bc52bb929f7cc0bb26cf9e7f019c953.tar.gz |
fix read/write for PharData object, update tests to current API
-rw-r--r-- | ext/phar/TODO | 2 | ||||
-rw-r--r-- | ext/phar/dirstream.c | 32 | ||||
-rw-r--r-- | ext/phar/phar.c | 2 | ||||
-rwxr-xr-x | ext/phar/phar_object.c | 95 | ||||
-rw-r--r-- | ext/phar/stream.c | 30 | ||||
-rw-r--r-- | ext/phar/tests/phar_convert_repeated.phpt | 30 | ||||
-rw-r--r-- | ext/phar/tests/phar_convert_repeated_b.phpt | 30 | ||||
-rw-r--r-- | ext/phar/tests/phar_convert_tar.phpt | 3 | ||||
-rw-r--r-- | ext/phar/tests/phar_convert_tar2.phpt | 6 | ||||
-rw-r--r-- | ext/phar/tests/phar_convert_tar3.phpt | 4 | ||||
-rw-r--r-- | ext/phar/tests/phar_convert_zip.phpt | 3 | ||||
-rw-r--r-- | ext/phar/tests/tar/phar_convert_phar.phpt | 12 | ||||
-rw-r--r-- | ext/phar/tests/tar/phar_convert_phar2.phpt | 7 | ||||
-rw-r--r-- | ext/phar/tests/tar/phar_convert_phar3.phpt | 7 | ||||
-rw-r--r-- | ext/phar/tests/tar/tar_makebz2.phpt | 3 | ||||
-rw-r--r-- | ext/phar/tests/tar/tar_makegz.phpt | 3 | ||||
-rw-r--r-- | ext/phar/tests/zf_test.phpt | 18 | ||||
-rw-r--r-- | ext/phar/tests/zip/phar_convert_phar.phpt | 9 | ||||
-rw-r--r-- | ext/phar/util.c | 16 |
19 files changed, 186 insertions, 126 deletions
diff --git a/ext/phar/TODO b/ext/phar/TODO index 9f38b059c9..945e7a5ccc 100644 --- a/ext/phar/TODO +++ b/ext/phar/TODO @@ -86,7 +86,7 @@ Version 2.0.0 X don't automatically add a stub to .zip or .tar files [Steph] X don't allow a stub or alias to be added to a .zip/.tar that does not have ".phar" in the filename (or already have stub/alias) [Steph] - X allow read/write on .tar/.zip files that do not contain a stub or alias [Steph] + X allow read/write on .tar/.zip files that do not contain a stub or alias [Steph/Greg] X prevent manual addition of stub via $a['.phar/stub.php'] = '<?php my stub'; [Greg] * investigate potential collision between SPL's DirectoryIterator flags and those in phar_archive_data diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index c33b55d292..14f13f9c6a 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -418,13 +418,23 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, int options, php_stream_context *context TSRMLS_DC) /* {{{ */ { phar_entry_info entry, *e; - phar_archive_data *phar; - char *error; + phar_archive_data *phar = NULL; + char *error, *arch, *entry2; + int arch_len, entry_len; char *plain_map; php_url *resource = NULL; uint host_len; - if (PHAR_G(readonly)) { + /* pre-readonly check, we need to know if this is a data phar */ + if (FAILURE == phar_split_fname(url_from, strlen(url_from), &arch, &arch_len, &entry2, &entry_len TSRMLS_CC)) { + return FAILURE; + } + if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { + phar = NULL; + } + efree(arch); + efree(entry2); + if (PHAR_G(readonly) && (!phar || !phar->is_data)) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\", write operations disabled", url_from); return FAILURE; } @@ -519,13 +529,23 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, in int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) /* {{{ */ { phar_entry_info *entry; - phar_archive_data *phar; - char *error; + phar_archive_data *phar = NULL; + char *error, *arch, *entry2; + int arch_len, entry_len; char *plain_map; php_url *resource = NULL; uint host_len; - if (PHAR_G(readonly)) { + /* pre-readonly check, we need to know if this is a data phar */ + if (FAILURE == phar_split_fname(url, strlen(url), &arch, &arch_len, &entry2, &entry_len TSRMLS_CC)) { + return FAILURE; + } + if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) { + phar = NULL; + } + efree(arch); + efree(entry2); + if (PHAR_G(readonly) && (!phar || !phar->is_data)) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot rmdir directory \"%s\", write operations disabled", url); return FAILURE; } diff --git a/ext/phar/phar.c b/ext/phar/phar.c index d94ab50acb..a8f551a016 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1827,7 +1827,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, *error = NULL; } - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar->is_data) { return EOF; } diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index a6ae41af4e..ce2356b5e4 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1496,7 +1496,7 @@ PHP_METHOD(Phar, buildFromIterator) } pass; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot write out phar archive, phar is read-only"); return; @@ -1687,12 +1687,19 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c if (!phar->is_data) { if (phar->alias) { - efree(phar->alias); - phar->alias = estrndup(newpath, strlen(newpath)); - phar->alias_len = strlen(newpath); - phar->is_temporary_alias = 1; - zend_hash_update(&(PHAR_GLOBALS->phar_alias_map), newpath, phar->fname_len, (void*)&phar, sizeof(phar_archive_data*), NULL); + if (phar->is_temporary_alias) { + phar->alias = NULL; + phar->alias_len = 0; + } else { + phar->alias = estrndup(newpath, strlen(newpath)); + phar->alias_len = strlen(newpath); + phar->is_temporary_alias = 1; + zend_hash_update(&(PHAR_GLOBALS->phar_alias_map), newpath, phar->fname_len, (void*)&phar, sizeof(phar_archive_data*), NULL); + } } + } else { + phar->alias = NULL; + phar->alias_len = 0; } @@ -1755,6 +1762,7 @@ static zval *phar_convert_to_other(phar_archive_data *source, int convert, char phar->fname = source->fname; phar->fname_len = source->fname_len; phar->is_temporary_alias = source->is_temporary_alias; + phar->alias = source->alias; /* first copy each file's uncompressed contents to a temporary file and set per-file flags */ for (zend_hash_internal_pointer_reset(&source->manifest); SUCCESS == zend_hash_has_more_elements(&source->manifest); zend_hash_move_forward(&source->manifest)) { @@ -1824,7 +1832,7 @@ static zval *phar_convert_to_other(phar_archive_data *source, int convert, char PHP_METHOD(Phar, convertToTar) { char *ext = NULL; - int ext_len = 0; + int ext_len = 0, save; zval *ret; PHAR_ARCHIVE_OBJECT(); @@ -1836,12 +1844,12 @@ PHP_METHOD(Phar, convertToTar) RETURN_TRUE; } if (PHAR_G(readonly)) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "Cannot write out phar archive, phar is read-only"); - return; + save = phar_obj->arc.archive->is_data; + phar_obj->arc.archive->is_data = 1; } ret = phar_convert_to_other(phar_obj->arc.archive, 1, ext, phar_obj->arc.archive->flags TSRMLS_CC); + phar_obj->arc.archive->is_data = save; if (ret) { RETURN_ZVAL(ret, 1, 1); } else { @@ -1858,7 +1866,7 @@ PHP_METHOD(Phar, convertToTar) PHP_METHOD(Phar, convertToZip) { char *ext = NULL; - int ext_len = 0; + int ext_len = 0, save; zval *ret; PHAR_ARCHIVE_OBJECT(); @@ -1871,12 +1879,12 @@ PHP_METHOD(Phar, convertToZip) } if (PHAR_G(readonly)) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "Cannot write out phar archive, phar is read-only"); - return; + save = phar_obj->arc.archive->is_data; + phar_obj->arc.archive->is_data = 1; } ret = phar_convert_to_other(phar_obj->arc.archive, 2, ext, PHAR_FILE_COMPRESSED_NONE TSRMLS_CC); + phar_obj->arc.archive->is_data = save; if (ret) { RETURN_ZVAL(ret, 1, 1); } else { @@ -2054,12 +2062,6 @@ PHP_METHOD(Phar, convertToData) RETURN_TRUE; } - if (PHAR_G(readonly)) { /* Don't override this one for is_data */ - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "Cannot convert phar archive to executable format, phar is read-only"); - return; - } - phar_obj->arc.archive->is_data = 1; if (phar_obj->arc.archive->is_tar) { ret = phar_convert_to_other(phar_obj->arc.archive, 1, ext, phar_obj->arc.archive->flags TSRMLS_CC); @@ -2103,7 +2105,7 @@ PHP_METHOD(Phar, delete) phar_entry_info *entry; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot write out phar archive, phar is read-only"); return; @@ -2174,7 +2176,7 @@ PHP_METHOD(Phar, setAlias) int alias_len, oldalias_len, old_temp, readd = 0; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot write out phar archive, phar is read-only"); RETURN_FALSE; @@ -2281,7 +2283,7 @@ PHP_METHOD(Phar, stopBuffering) char *error; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot write out phar archive, phar is read-only"); return; @@ -2310,7 +2312,7 @@ PHP_METHOD(Phar, setStub) php_stream *stream; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot change stub, phar is read-only"); return; @@ -2437,7 +2439,7 @@ PHP_METHOD(Phar, setSignatureAlgorithm) char *error; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot set signature algorithm, phar is read-only"); return; @@ -2585,7 +2587,7 @@ PHP_METHOD(Phar, compressAllFilesGZ) char *error; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); return; @@ -2625,7 +2627,7 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) char *error; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); return; @@ -2665,7 +2667,7 @@ PHP_METHOD(Phar, uncompressAllFiles) char *error; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); return; @@ -2707,7 +2709,7 @@ PHP_METHOD(Phar, copy) return; } - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Cannot copy \"%s\" to \"%s\", phar is read-only", oldfile, newfile); RETURN_FALSE; @@ -2851,7 +2853,7 @@ PHP_METHOD(Phar, offsetSet) php_stream *contents_file; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); return; } @@ -2918,7 +2920,7 @@ PHP_METHOD(Phar, offsetUnset) phar_entry_info *entry; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); return; } @@ -3069,7 +3071,7 @@ PHP_METHOD(Phar, setMetadata) zval *metadata; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); return; } @@ -3106,10 +3108,15 @@ PHP_METHOD(Phar, delMetadata) char *error; PHAR_ARCHIVE_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !phar_obj->arc.archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); return; } + if (phar_obj->arc.archive->is_tar) { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, + "Cannot delete metadata, not possible with tar-based phar archives"); + return; + } if (phar_obj->arc.archive->metadata) { zval_ptr_dtor(&phar_obj->arc.archive->metadata); phar_obj->arc.archive->metadata = NULL; @@ -3321,7 +3328,7 @@ PHP_METHOD(PharFileInfo, chmod) "Phar entry is a directory, cannot chmod"); \ return; } - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" in phar \"%s\", write operations are prohibited", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname); return; } @@ -3387,7 +3394,7 @@ PHP_METHOD(PharFileInfo, setMetadata) zval *metadata; PHAR_ENTRY_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); return; } @@ -3429,10 +3436,15 @@ PHP_METHOD(PharFileInfo, delMetadata) char *error; PHAR_ENTRY_OBJECT(); - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Write operations disabled by INI setting"); return; } + if (entry_obj->ent.entry->is_tar) { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, + "Cannot delete metadata, not possible with tar-based phar archives"); + return; + } if (entry_obj->ent.entry->is_temp_dir) { RETURN_FALSE; } @@ -3476,7 +3488,7 @@ PHP_METHOD(PharFileInfo, setCompressedGZ) RETURN_TRUE; return; } - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); return; @@ -3514,11 +3526,6 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2) char *error; PHAR_ENTRY_OBJECT(); - if (entry_obj->ent.entry->is_zip) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress with Bzip2 compression, not possible with zip-based phar archives"); - return; - } if (entry_obj->ent.entry->is_tar) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress with Bzip2 compression, not possible with tar-based phar archives"); @@ -3537,7 +3544,7 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2) if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) { RETURN_TRUE; } - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); return; @@ -3580,7 +3587,7 @@ PHP_METHOD(PharFileInfo, setUncompressed) RETURN_TRUE; return; } - if (PHAR_G(readonly)) { + if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); return; diff --git a/ext/phar/stream.c b/ext/phar/stream.c index dc32d25ae1..0d73908d53 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -109,7 +109,12 @@ php_url* phar_open_url(php_stream_wrapper *wrapper, char *filename, char *mode, return resource; } if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { - if (PHAR_G(readonly)) { + phar_archive_data **pphar = NULL; + + if (PHAR_GLOBALS->request_init && PHAR_GLOBALS->phar_fname_map.arBuckets && FAILURE == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **)&pphar)) { + pphar = NULL; + } + if (PHAR_G(readonly) && (!pphar || !(*pphar)->is_data)) { if (!(options & PHP_STREAM_URL_STAT_QUIET)) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting"); } @@ -670,6 +675,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio php_url *resource; char *internal_file, *error, *plain_map; phar_entry_data *idata; + phar_archive_data **pphar; uint host_len; int retval; @@ -703,7 +709,10 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio return retval; } - if (PHAR_G(readonly)) { + if (FAILURE == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), resource->host, strlen(resource->host), (void **) &pphar)) { + pphar = NULL; + } + if (PHAR_G(readonly) && (!pphar || !(*pphar)->is_data)) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting"); return 0; @@ -753,15 +762,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char { php_url *resource_from, *resource_to; char *error, *plain_map; - phar_archive_data *phar; + phar_archive_data *phar, *pfrom, *pto; phar_entry_info *entry; uint host_len; error = NULL; - if (PHAR_G(readonly)) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting"); - return 0; - } if ((resource_from = phar_open_url(wrapper, url_from, "r+b", options TSRMLS_CC)) == NULL) { return 0; @@ -772,6 +777,17 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char return 0; } + if (SUCCESS != phar_get_archive(&pfrom, resource_from->host, strlen(resource_from->host), NULL, 0, &error TSRMLS_CC)) { + pfrom = NULL; + } + if (SUCCESS != phar_get_archive(&pto, resource_to->host, strlen(resource_to->host), NULL, 0, &error TSRMLS_CC)) { + pto = NULL; + } + if (PHAR_G(readonly) && ((!pfrom || !pfrom->is_data) || (!pto || !pto->is_data))) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting"); + return 0; + } + /* we must have at the very least phar://alias.phar/internalfile.php */ if (!resource_from->scheme || !resource_from->host || !resource_from->path) { php_url_free(resource_from); diff --git a/ext/phar/tests/phar_convert_repeated.phpt b/ext/phar/tests/phar_convert_repeated.phpt index 480d7900c7..ab6ec8aba6 100644 --- a/ext/phar/tests/phar_convert_repeated.phpt +++ b/ext/phar/tests/phar_convert_repeated.phpt @@ -32,7 +32,7 @@ var_dump($phar->getAlias()); echo "================= convertToTar() =====================\n"; -$phar->convertToTar(); +$phar = $phar->convertToTar(); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -41,7 +41,7 @@ var_dump($phar->getAlias()); echo "================= convertToZip() =====================\n"; -$phar->convertToZip(); +$phar = $phar->convertToZip(); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -50,7 +50,7 @@ var_dump($phar->getAlias()); echo "================= convertToPhar() ====================\n"; -$phar->convertToPhar(); +$phar = $phar->convertToPhar('.2.phar'); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -59,7 +59,7 @@ var_dump($phar->getAlias()); echo "================= convertToZip() =====================\n"; -$phar->convertToZip(); +$phar = $phar->convertToZip('.2.phar.zip'); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -68,7 +68,7 @@ var_dump($phar->getAlias()); echo "================= convertToTar() =====================\n"; -$phar->convertToTar(); +$phar = $phar->convertToTar('2.phar.tar'); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -77,7 +77,7 @@ var_dump($phar->getAlias()); echo "================= convertToZip() =====================\n"; -$phar->convertToZip(); +$phar = $phar->convertToZip('3.phar.zip'); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -89,6 +89,14 @@ var_dump($phar->getAlias()); --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.zip'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar'); ?> --EXPECTF-- =================== new Phar() ======================= @@ -110,32 +118,32 @@ bool(false) bool(true) string(60) "<?php // zip-based phar archive stub file __HALT_COMPILER();" -string(%d) "%sphar_convert_repeated.phar.zip" +NULL ================= convertToPhar() ==================== bool(true) bool(false) bool(false) int(6651) -string(%d) "%sphar_convert_repeated.phar" +NULL ================= convertToZip() ===================== bool(false) bool(false) bool(true) string(60) "<?php // zip-based phar archive stub file __HALT_COMPILER();" -string(%d) "%sphar_convert_repeated.phar.zip" +NULL ================= convertToTar() ===================== bool(false) bool(true) bool(false) string(60) "<?php // tar-based phar archive stub file __HALT_COMPILER();" -string(%d) "%sphar_convert_repeated.phar.tar" +NULL ================= convertToZip() ===================== bool(false) bool(false) bool(true) string(60) "<?php // zip-based phar archive stub file __HALT_COMPILER();" -string(%d) "%sphar_convert_repeated.phar.zip" +NULL ===DONE=== diff --git a/ext/phar/tests/phar_convert_repeated_b.phpt b/ext/phar/tests/phar_convert_repeated_b.phpt index 229d654a0d..6ed0070270 100644 --- a/ext/phar/tests/phar_convert_repeated_b.phpt +++ b/ext/phar/tests/phar_convert_repeated_b.phpt @@ -3,7 +3,7 @@ PharData::convertToZip|Tar|Phar() repeated (phardata_based archives) --SKIPIF-- <?php if (!extension_loaded("phar")) die("skip"); ?> --INI-- -phar.readonly=0 +phar.readonly=1 --FILE-- <?php @@ -54,7 +54,7 @@ try { echo "================ convertToTar(GZ) ====================\n"; -$phar = $phar->convertToTar()->compress(Phar::GZ); +$phar = $phar->convertToTar('.2.tar')->compress(Phar::GZ); var_dump($phar->isPhar()); var_dump($phar->isTar()); var_dump($phar->isZip()); @@ -78,16 +78,14 @@ try { ===DONE=== --CLEAN-- <?php -unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); -unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); -unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.gz'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar.gz'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); -unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.zip'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.zip'); ?> ---EXPECTF-- +--EXPECT-- =================== new PharData() ================== bool(false) bool(false) @@ -107,23 +105,13 @@ bool(true) string(0) "" NULL ================= convertToPhar() ==================== -bool(true) -bool(false) -bool(false) -int(6651) -NULL +Cannot write out phar archive, phar is read-only ================ convertToTar(GZ) ==================== bool(false) bool(true) bool(false) -string(60) "<?php // tar-based phar archive stub file -__HALT_COMPILER();" +string(0) "" NULL ================= convertToPhar() ==================== -bool(true) -bool(false) -bool(false) -int(6651) -NULL -===DONE=== - +Cannot write out phar archive, phar is read-only +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/phar_convert_tar.phpt b/ext/phar/tests/phar_convert_tar.phpt index dc5db0c7af..92ff1e36d7 100644 --- a/ext/phar/tests/phar_convert_tar.phpt +++ b/ext/phar/tests/phar_convert_tar.phpt @@ -26,7 +26,7 @@ $phar = new Phar($fname); var_dump($phar->isTar()); var_dump($phar->getStub()); -$phar->convertToTar(); +$phar = $phar->convertToTar(); var_dump($phar->isTar()); var_dump($phar->getStub()); @@ -41,6 +41,7 @@ var_dump($phar->getStub()); --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar'); __HALT_COMPILER(); ?> diff --git a/ext/phar/tests/phar_convert_tar2.phpt b/ext/phar/tests/phar_convert_tar2.phpt index 16d3a068e2..edb2e1eef0 100644 --- a/ext/phar/tests/phar_convert_tar2.phpt +++ b/ext/phar/tests/phar_convert_tar2.phpt @@ -12,7 +12,7 @@ phar.readonly=0 $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; $pname = 'phar://' . $fname; $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.gz'; -$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar'; $stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'; $file = $stub; @@ -28,7 +28,7 @@ var_dump($phar->isTar()); var_dump($phar->isCompressed()); var_dump($phar->getStub()); -$phar->convertToTar(Phar::GZ); +$phar = $phar->convertToTar()->compress(Phar::GZ); var_dump($phar->isTar()); var_dump($phar->isCompressed()); var_dump($phar->getStub()); @@ -46,6 +46,8 @@ var_dump($phar->getStub()); <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> --EXPECT-- bool(false) diff --git a/ext/phar/tests/phar_convert_tar3.phpt b/ext/phar/tests/phar_convert_tar3.phpt index 515de3ffb4..91e2fc5a36 100644 --- a/ext/phar/tests/phar_convert_tar3.phpt +++ b/ext/phar/tests/phar_convert_tar3.phpt @@ -28,7 +28,7 @@ var_dump($phar->isTar()); var_dump($phar->isCompressed()); var_dump($phar->getStub()); -$phar->convertToTar(Phar::BZ2); +$phar = $phar->convertToTar()->compress(Phar::BZ2); var_dump($phar->isTar()); var_dump($phar->isCompressed()); var_dump($phar->getStub()); @@ -46,6 +46,8 @@ var_dump($phar->getStub()); <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.bz2'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); __HALT_COMPILER(); ?> --EXPECT-- diff --git a/ext/phar/tests/phar_convert_zip.phpt b/ext/phar/tests/phar_convert_zip.phpt index f99bda2d17..c9e9769917 100644 --- a/ext/phar/tests/phar_convert_zip.phpt +++ b/ext/phar/tests/phar_convert_zip.phpt @@ -26,7 +26,7 @@ $phar = new Phar($fname); var_dump($phar->isZip()); var_dump($phar->getStub()); -$phar->convertToZip(); +$phar = $phar->convertToZip(); var_dump($phar->isZip()); var_dump($phar->getStub()); @@ -41,6 +41,7 @@ var_dump($phar->getStub()); --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip'); __HALT_COMPILER(); ?> diff --git a/ext/phar/tests/tar/phar_convert_phar.phpt b/ext/phar/tests/tar/phar_convert_phar.phpt index 9697329f1b..dea5a78af6 100644 --- a/ext/phar/tests/tar/phar_convert_phar.phpt +++ b/ext/phar/tests/tar/phar_convert_phar.phpt @@ -10,23 +10,24 @@ phar.readonly=0 $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar'; +$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar'; $phar = new Phar($fname); $phar->stopBuffering(); var_dump($phar->isTar()); var_dump(strlen($phar->getStub())); -$phar->convertToTar(); +$phar = $phar->convertToTar(); var_dump($phar->isTar()); var_dump($phar->getStub()); $phar['a'] = 'hi there'; -$phar->convertToPhar(); +$phar = $phar->convertToPhar('.3.phar'); var_dump($phar->isPhar()); var_dump(strlen($phar->getStub())); -copy($fname, $fname2); +copy($fname3, $fname2); $phar = new Phar($fname2); var_dump($phar->isPhar()); @@ -37,7 +38,10 @@ var_dump(strlen($phar->getStub())); --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); -unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar'); __HALT_COMPILER(); ?> --EXPECT-- diff --git a/ext/phar/tests/tar/phar_convert_phar2.phpt b/ext/phar/tests/tar/phar_convert_phar2.phpt index 4bfda39069..27113728e1 100644 --- a/ext/phar/tests/tar/phar_convert_phar2.phpt +++ b/ext/phar/tests/tar/phar_convert_phar2.phpt @@ -17,13 +17,13 @@ $phar->stopBuffering(); var_dump($phar->isTar()); var_dump(strlen($phar->getStub())); -$phar->convertToTar(); +$phar = $phar->convertToTar(); var_dump($phar->isTar()); var_dump($phar->getStub()); $phar['a'] = 'hi there'; -$phar->convertToPhar(Phar::GZ); +$phar = $phar->compress(Phar::GZ)->convertToPhar(); var_dump($phar->isPhar()); var_dump($phar->isCompressed()); var_dump(strlen($phar->getStub())); @@ -39,7 +39,10 @@ var_dump(strlen($phar->getStub())); ===DONE=== --CLEAN-- <?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.gz'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar'); __HALT_COMPILER(); ?> diff --git a/ext/phar/tests/tar/phar_convert_phar3.phpt b/ext/phar/tests/tar/phar_convert_phar3.phpt index b8b3104a08..af2552e31e 100644 --- a/ext/phar/tests/tar/phar_convert_phar3.phpt +++ b/ext/phar/tests/tar/phar_convert_phar3.phpt @@ -17,13 +17,13 @@ $phar->stopBuffering(); var_dump($phar->isTar()); var_dump(strlen($phar->getStub())); -$phar->convertToTar(); +$phar = $phar->convertToTar(); var_dump($phar->isTar()); var_dump($phar->getStub()); $phar['a'] = 'hi there'; -$phar->convertToPhar(Phar::BZ2); +$phar = $phar->compress(Phar::BZ2)->convertToPhar(); var_dump($phar->isPhar()); var_dump($phar->isCompressed()); var_dump(strlen($phar->getStub())); @@ -41,6 +41,9 @@ var_dump(strlen($phar->getStub())); <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.bz2'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.bz2'); __HALT_COMPILER(); ?> --EXPECT-- diff --git a/ext/phar/tests/tar/tar_makebz2.phpt b/ext/phar/tests/tar/tar_makebz2.phpt index f72670f7a1..90379fa97a 100644 --- a/ext/phar/tests/tar/tar_makebz2.phpt +++ b/ext/phar/tests/tar/tar_makebz2.phpt @@ -16,7 +16,7 @@ $fname3 = dirname(__FILE__) . '/tar_makebz2_b.phar.tar.bz2'; $phar = new Phar($fname); $phar['test'] = 'hi'; var_dump($phar->isTar()); -$phar->compressAllFilesBZIP2(); +$phar = $phar->compress(Phar::BZ2); copy($fname2, $fname3); @@ -28,6 +28,7 @@ var_dump($phar2->isCompressed() == Phar::BZ2); ===DONE=== --CLEAN-- <?php +@unlink(dirname(__FILE__) . '/tar_makebz2.phar.tar'); @unlink(dirname(__FILE__) . '/tar_makebz2.phar.tar.bz2'); @unlink(dirname(__FILE__) . '/tar_makebz2_b.phar.tar.bz2'); ?> diff --git a/ext/phar/tests/tar/tar_makegz.phpt b/ext/phar/tests/tar/tar_makegz.phpt index 0d781c7fdd..805330e4c2 100644 --- a/ext/phar/tests/tar/tar_makegz.phpt +++ b/ext/phar/tests/tar/tar_makegz.phpt @@ -16,7 +16,7 @@ $fname3 = dirname(__FILE__) . '/tar_makegz_b.phar.tar.gz'; $phar = new Phar($fname); $phar['test'] = 'hi'; var_dump($phar->isTar()); -$phar->compressAllFilesGZ(); +$phar = $phar->compress(Phar::GZ); copy($fname2, $fname3); @@ -28,6 +28,7 @@ var_dump($phar2->isCompressed() == Phar::GZ); ===DONE=== --CLEAN-- <?php +@unlink(dirname(__FILE__) . '/tar_makegz.phar.tar'); @unlink(dirname(__FILE__) . '/tar_makegz.phar.tar.gz'); @unlink(dirname(__FILE__) . '/tar_makegz_b.phar.tar.gz'); ?> diff --git a/ext/phar/tests/zf_test.phpt b/ext/phar/tests/zf_test.phpt index bc3580fb06..5d1dbcbc43 100644 --- a/ext/phar/tests/zf_test.phpt +++ b/ext/phar/tests/zf_test.phpt @@ -10,12 +10,11 @@ phar.readonly=0 $file = "zfapp"; $orig_file = dirname(__FILE__) . "/files/$file.tgz"; $tgz_file = dirname(__FILE__) . "/$file.tgz"; -$phar_file = dirname(__FILE__) . "/$file.phar"; +$phar_file = dirname(__FILE__) . "/$file.phar.tar.gz"; copy($orig_file, $tgz_file); $phar = new PharData($tgz_file); -$phar->convertToPhar(); -$phar->stopBuffering(); +$phar = $phar->convertToExecutable(); $phar = new Phar($phar_file); $phar->startBuffering(); @@ -39,10 +38,11 @@ foreach(new RecursiveIteratorIterator($phar) as $path) { unlink(dirname(__FILE__) . '/zfapp.phar'); ?> --EXPECTF-- -phar://%szfapp.phar/application/default/controllers/ErrorController.php -phar://%szfapp.phar/application/default/controllers/IndexController.php -phar://%szfapp.phar/application/default/views/scripts/error/error.phtml -phar://%szfapp.phar/application/default/views/scripts/index/index.phtml -phar://%szfapp.phar/html/.htaccess -phar://%szfapp.phar/html/index.php +phar://%szfapp.phar.tar.gz/.phar/stub.php +phar://%szfapp.phar.tar.gz/application/default/controllers/ErrorController.php +phar://%szfapp.phar.tar.gz/application/default/controllers/IndexController.php +phar://%szfapp.phar.tar.gz/application/default/views/scripts/error/error.phtml +phar://%szfapp.phar.tar.gz/application/default/views/scripts/index/index.phtml +phar://%szfapp.phar.tar.gz/html/.htaccess +phar://%szfapp.phar.tar.gz/html/index.php ===DONE=== diff --git a/ext/phar/tests/zip/phar_convert_phar.phpt b/ext/phar/tests/zip/phar_convert_phar.phpt index 59aad1cdc9..70ba863a69 100644 --- a/ext/phar/tests/zip/phar_convert_phar.phpt +++ b/ext/phar/tests/zip/phar_convert_phar.phpt @@ -10,23 +10,24 @@ phar.readonly=0 $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; $fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar'; +$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar'; $phar = new Phar($fname); $phar->stopBuffering(); var_dump($phar->isZip()); var_dump(strlen($phar->getStub())); -$phar->convertToZip(); +$phar = $phar->convertToZip(); var_dump($phar->isZip()); var_dump($phar->getStub()); $phar['a'] = 'hi there'; -$phar->convertToPhar(); +$phar = $phar->convertToPhar('.3.phar'); var_dump($phar->isPhar()); var_dump(strlen($phar->getStub())); -copy($fname, $fname2); +copy($fname3, $fname2); $phar = new Phar($fname2); var_dump($phar->isPhar()); @@ -37,7 +38,9 @@ var_dump(strlen($phar->getStub())); --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar'); __HALT_COMPILER(); ?> --EXPECT-- diff --git a/ext/phar/util.c b/ext/phar/util.c index d3f198c9be..6c496650a8 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -420,15 +420,15 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char if (error) { *error = NULL; } - if (for_write && PHAR_G(readonly)) { + if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) { + return FAILURE; + } + if (for_write && PHAR_G(readonly) && !phar->is_data) { if (error) { spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, fname); } return FAILURE; } - if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) { - return FAILURE; - } if (!path_len) { if (error) { spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" cannot be empty", fname); @@ -436,15 +436,15 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char return FAILURE; } if (allow_dir) { - if ((entry = phar_get_entry_info_dir(phar, path, path_len, 2, for_create && !PHAR_G(readonly) ? NULL : error TSRMLS_CC)) == NULL) { - if (for_create && !PHAR_G(readonly)) { + if ((entry = phar_get_entry_info_dir(phar, path, path_len, 2, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error TSRMLS_CC)) == NULL) { + if (for_create && (!PHAR_G(readonly) || phar->is_data)) { return SUCCESS; } return FAILURE; } } else { - if ((entry = phar_get_entry_info(phar, path, path_len, for_create && !PHAR_G(readonly) ? NULL : error TSRMLS_CC)) == NULL) { - if (for_create && !PHAR_G(readonly)) { + if ((entry = phar_get_entry_info(phar, path, path_len, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error TSRMLS_CC)) == NULL) { + if (for_create && (!PHAR_G(readonly) || phar->is_data)) { return SUCCESS; } return FAILURE; |