From: Greg Beaver Date: Tue, 15 Jan 2008 23:41:44 +0000 (+0000) Subject: add support for creation of gzipped and bzipped tar-based phars X-Git-Tag: RELEASE_2_0_0a1~885 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb40b39b5bcabb4688ec594454babc5bf2b8ce02;p=php add support for creation of gzipped and bzipped tar-based phars --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 87fb6c84cb..7e9d614297 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1708,11 +1708,6 @@ PHP_METHOD(Phar, compressAllFilesGZ) #endif PHAR_ARCHIVE_OBJECT(); - if (phar_obj->arc.archive->is_tar) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress all files as Gzip, not possible with tar-based phar archives"); - return; - } if (PHAR_G(readonly)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Phar is readonly, cannot change compression"); @@ -1729,7 +1724,12 @@ PHP_METHOD(Phar, compressAllFilesGZ) "Cannot compress all files as Gzip, some are compressed as bzip2 and cannot be uncompressed"); return; } - pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_GZ TSRMLS_CC); + if (phar_obj->arc.archive->is_tar) { + phar_obj->arc.archive->flags &= ~PHAR_FILE_COMPRESSION_MASK; + phar_obj->arc.archive->flags |= PHAR_FILE_COMPRESSED_GZ; + } else { + pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_GZ TSRMLS_CC); + } phar_obj->arc.archive->is_modified = 1; phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC); @@ -1754,11 +1754,6 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) #endif PHAR_ARCHIVE_OBJECT(); - if (phar_obj->arc.archive->is_tar) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress all files as Bzip2, not possible with tar-based phar archives"); - return; - } if (phar_obj->arc.archive->is_zip) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress all files as Bzip2, not possible with zip-based phar archives"); @@ -1781,7 +1776,12 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) "Cannot compress all files as Bzip2, some are compressed as gzip and cannot be uncompressed"); return; } - pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_BZ2 TSRMLS_CC); + if (phar_obj->arc.archive->is_tar) { + phar_obj->arc.archive->flags &= ~PHAR_FILE_COMPRESSION_MASK; + phar_obj->arc.archive->flags |= PHAR_FILE_COMPRESSED_BZ2; + } else { + pharobj_set_compression(&phar_obj->arc.archive->manifest, PHAR_ENT_COMPRESSED_BZ2 TSRMLS_CC); + } phar_obj->arc.archive->is_modified = 1; phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC); diff --git a/ext/phar/tests/tar/tar_makebz2.phpt b/ext/phar/tests/tar/tar_makebz2.phpt new file mode 100644 index 0000000000..3dd2735277 --- /dev/null +++ b/ext/phar/tests/tar/tar_makebz2.phpt @@ -0,0 +1,36 @@ +--TEST-- +Phar: tar-based phar, make new bzipped tar +--SKIPIF-- + + + +--INI-- +phar.readonly=0 +--FILE-- +isTar()); +$a->compressAllFilesBZIP2(); +copy($fname, $fname2); +$b = new Phar($fname2); +var_dump($b->isTar()); +var_dump($b->isCompressed() == Phar::BZ2); +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +bool(true) +bool(true) +bool(true) +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/tar/tar_makegz.phpt b/ext/phar/tests/tar/tar_makegz.phpt new file mode 100644 index 0000000000..bf5c065d83 --- /dev/null +++ b/ext/phar/tests/tar/tar_makegz.phpt @@ -0,0 +1,36 @@ +--TEST-- +Phar: tar-based phar, make new gzipped tar +--SKIPIF-- + + + +--INI-- +phar.readonly=0 +--FILE-- +isTar()); +$a->compressAllFilesGZ(); +copy($fname, $fname2); +$b = new Phar($fname2); +var_dump($b->isTar()); +var_dump($b->isCompressed() == Phar::GZ); +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +bool(true) +bool(true) +bool(true) +===DONE=== \ No newline at end of file