streams interface [Greg]
X Phar archive metadata Phar::setMetaData($metadata) Phar::getMetaData() [Greg]
X support rename() in stream wrapper [Greg]
- * update docs to reflect changes in error handling
- * fix 011.phpt, 029.phpt for uncaught exceptions causing bad cleanup
+ X update docs to reflect changes in error handling [Greg]
+ X fix 011.phpt, 029.phpt for uncaught exceptions causing bad cleanup [Marcus/Greg]
Version 1.1.0
efree(data->alias);
data->alias = NULL;
}
- efree(data->fname);
+ if (data->fname) {
+ efree(data->fname);
+ }
if (data->signature) {
efree(data->signature);
}
phar_archive_data *phar_data = *(phar_archive_data **) pDest;
TSRMLS_FETCH();
- if (--phar_data->refcount < 0) {
+ if (EG(exception) || --phar_data->refcount < 0) {
phar_destroy_phar_data(phar_data TSRMLS_CC);
}
}
#define MAPPHAR_FAIL(msg) \
efree(savebuf);\
if (mydata) {\
- efree(mydata);\
+ phar_destroy_phar_data(mydata TSRMLS_CC);\
}\
if (signature) {\
efree(signature);\
PHAR_GET_32(buffer, entry.flags);
if (*(php_uint32 *) buffer) {
if (phar_parse_metadata(fp, &buffer, endbuffer, &entry.metadata TSRMLS_CC) == FAILURE) {
+ efree(entry.filename);
MAPPHAR_FAIL("unable to read file metadata in .phar file \"%s\"");
}
} else {
switch (entry.flags & PHAR_ENT_COMPRESSION_MASK) {
case PHAR_ENT_COMPRESSED_GZ:
#if !HAVE_ZLIB
+ if (entry.metadata) {
+ zval_ptr_dtor(&entry.metadata);
+ }
+ efree(entry.filename);
MAPPHAR_FAIL("zlib extension is required for gz compressed .phar file \"%s\"");
#endif
break;
case PHAR_ENT_COMPRESSED_BZ2:
#if !HAVE_BZ2
+ if (entry.metadata) {
+ zval_ptr_dtor(&entry.metadata);
+ }
+ efree(entry.filename);
MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\"");
#endif
break;
default:
if (entry.uncompressed_filesize != entry.compressed_filesize) {
+ if (entry.metadata) {
+ zval_ptr_dtor(&entry.metadata);
+ }
+ efree(entry.filename);
MAPPHAR_FAIL("internal corruption of phar \"%s\" (compressed and uncompressed size does not match for uncompressed entry)");
}
break;
/* we must have at the very least phar://alias.phar/ */
if (!resource->scheme || !resource->host || !resource->path) {
if (resource->host && !resource->path) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory", path, resource->host);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, resource->host);
php_url_free(resource);
return NULL;
}
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Phar is readonly, cannot change compression");
}
#if HAVE_ZLIB
if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Cannot compress all files as Gzip, some are compressed as bzip2 and cannot be uncompressed");
}
pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_GZ TSRMLS_CC);
phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC);
if (error) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error);
efree(error);
}
#else
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Cannot compress with Gzip compression, zlib extension is not enabled");
#endif
}
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Phar is readonly, cannot change compression");
}
#if HAVE_BZ2
if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Cannot compress all files as Bzip2, some are compressed as gzip and cannot be uncompressed");
}
pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_BZ2 TSRMLS_CC);
phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC);
if (error) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error);
efree(error);
}
#else
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Cannot compress with Bzip2 compression, bz2 extension is not enabled");
#endif
}
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Phar is readonly, cannot change compression");
}
if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
"Cannot uncompress all files, some are compressed as bzip2 or gzip and cannot be uncompressed");
}
pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_NONE TSRMLS_CC);
phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC);
if (error) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error);
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error);
efree(error);
}
}
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
--EXPECTF--
-Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory in %s on line %d
+Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory (always use full path to a new phar) in %s on line %d
--TEST--
-Phar: create a Phar with relative path
+Phar: attempt to create a Phar with relative path
--SKIPIF--
<?php if (!extension_loaded("phar")) print "skip"; ?>
--INI--
--FILE--
<?php
chdir(dirname(__FILE__));
-$p = new Phar('brandnewphar.phar');
-$p['file1.txt'] = 'hi';
-$p->commit();
-var_dump($p->getStub());
-$p->setStub("<?php
+try {
+ $p = new Phar('brandnewphar.phar');
+ $p['file1.txt'] = 'hi';
+ $p->commit();
+ var_dump($p->getStub());
+ $p->setStub("<?php
function __autoload(\$class)
{
include 'phar://' . str_replace('_', '/', \$class);
include 'phar://brandnewphar.phar/startup.php';
__HALT_COMPILER();
?>");
-var_dump($p->getStub());
+ var_dump($p->getStub());
+} catch (Exception $e) {
+ echo $e->getMessage() . "\n";
+}
?>
===DONE===
--CLEAN--
unlink(dirname(__FILE__) . '/brandnewphar.phar');
?>
--EXPECT--
-string(24) "<?php __HALT_COMPILER();"
-string(198) "<?php
-function __autoload($class)
-{
- include 'phar://' . str_replace('_', '/', $class);
-}
-Phar::mapPhar('brandnewphar.phar');
-include 'phar://brandnewphar.phar/startup.php';
-__HALT_COMPILER();
-?>"
+RecursiveDirectoryIterator::__construct(phar://brandnewphar.phar): failed to open dir: phar error: no directory in "phar://brandnewphar.phar", must have at least phar://brandnewphar.phar/ for root directory (always use full path to a new phar)
===DONE===
\ No newline at end of file