mirror of
https://github.com/php/php-src.git
synced 2024-09-23 10:57:26 +00:00
rework PharFileInfo->decompress and add failing test
This commit is contained in:
parent
d28dcfaf60
commit
0db641af3e
@ -3741,7 +3741,7 @@ PHP_METHOD(PharFileInfo, compress)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ) != 0 && !phar_has_zlib) {
|
||||
if (!phar_has_zlib) {
|
||||
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
|
||||
"Cannot compress with gzip compression, zlib extension is not enabled");
|
||||
return;
|
||||
@ -3769,6 +3769,11 @@ PHP_METHOD(PharFileInfo, compress)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!phar_has_bz2) {
|
||||
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
|
||||
"Cannot compress with bzip2 compression, bz2 extension is not enabled");
|
||||
return;
|
||||
}
|
||||
entry_obj->ent.entry->old_flags = entry_obj->ent.entry->flags;
|
||||
entry_obj->ent.entry->flags &= ~PHAR_ENT_COMPRESSION_MASK;
|
||||
entry_obj->ent.entry->flags |= PHAR_ENT_COMPRESSED_BZ2;
|
||||
@ -3795,8 +3800,7 @@ PHP_METHOD(PharFileInfo, compress)
|
||||
*/
|
||||
PHP_METHOD(PharFileInfo, decompress)
|
||||
{
|
||||
char *fname, *error;
|
||||
int fname_len;
|
||||
char *error;
|
||||
PHAR_ENTRY_OBJECT();
|
||||
|
||||
if (entry_obj->ent.entry->is_dir) {
|
||||
@ -3810,7 +3814,7 @@ PHP_METHOD(PharFileInfo, decompress)
|
||||
}
|
||||
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");
|
||||
"Phar is readonly, cannot decompress");
|
||||
return;
|
||||
}
|
||||
if (entry_obj->ent.entry->is_deleted) {
|
||||
@ -3829,9 +3833,11 @@ PHP_METHOD(PharFileInfo, decompress)
|
||||
return;
|
||||
}
|
||||
if (!entry_obj->ent.entry->fp) {
|
||||
fname_len = spprintf(&fname, 0, "phar://%s/%s", entry_obj->ent.entry->phar->fname, entry_obj->ent.entry->filename);
|
||||
entry_obj->ent.entry->fp = php_stream_open_wrapper_ex(fname, "rb", 0, 0, 0);
|
||||
efree(fname);
|
||||
if (FAILURE == phar_open_archive_fp(entry_obj->ent.entry->phar TSRMLS_CC)) {
|
||||
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot decompress entry \"%s\", phar error: Cannot open phar archive \"%s\" for reading", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname);
|
||||
return;
|
||||
}
|
||||
entry_obj->ent.entry->fp_type = PHAR_FP;
|
||||
}
|
||||
entry_obj->ent.entry->old_flags = entry_obj->ent.entry->flags;
|
||||
entry_obj->ent.entry->flags &= ~PHAR_ENT_COMPRESSION_MASK;
|
||||
|
88
ext/phar/tests/pharfileinfo_compression.phpt
Normal file
88
ext/phar/tests/pharfileinfo_compression.phpt
Normal file
@ -0,0 +1,88 @@
|
||||
--TEST--
|
||||
Phar: PharFileInfo compression-related methods
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
<?php if (!extension_loaded("zlib")) die("skip no zlib"); ?>
|
||||
<?php if (!extension_loaded("bz2")) die("skip no bz2"); ?>
|
||||
--INI--
|
||||
phar.readonly=0
|
||||
--FILE--
|
||||
<?php
|
||||
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar';
|
||||
$pname = 'phar://' . $fname;
|
||||
|
||||
$phar = new Phar($fname);
|
||||
|
||||
$phar['a/b'] = 'hi there';
|
||||
|
||||
$b = $phar['a/b'];
|
||||
|
||||
$b->isCompressed(array());
|
||||
try {
|
||||
$b->isCompressed(25);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
try {
|
||||
$b->compress(25);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
$tar = $phar->convertToData(Phar::TAR);
|
||||
|
||||
$c = $tar['a/b'];
|
||||
try {
|
||||
$c->compress(Phar::GZ);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
try {
|
||||
$phar['a']->compress(Phar::GZ);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
ini_set('phar.readonly', 1);
|
||||
try {
|
||||
$b->compress(Phar::GZ);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
ini_set('phar.readonly', 0);
|
||||
var_dump($b->compress(Phar::GZ));
|
||||
var_dump($b->compress(Phar::GZ));
|
||||
var_dump($b->compress(Phar::BZ2));
|
||||
var_dump($b->compress(Phar::BZ2));
|
||||
|
||||
echo "decompress\n";
|
||||
|
||||
try {
|
||||
$phar['a/b']->decompress();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
ini_set('phar.readonly', 1);
|
||||
try {
|
||||
$b->decompress();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
ini_set('phar.readonly', 0);
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--CLEAN--
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
|
||||
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); ?>
|
||||
--EXPECT--
|
||||
Warning: PharFileInfo::isCompressed() expects parameter 1 to be long, array given in %spharfileinfo_compression.php on line 11
|
||||
Unknown compression type specified
|
||||
Unknown compression type specified
|
||||
Cannot compress with Gzip compression, not possible with tar-based phar archives
|
||||
Phar entry is a directory, cannot set compression
|
||||
Phar is readonly, cannot change compression
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
decompress
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user