cellog Fri Apr 11 13:26:02 2008 UTC
Modified files:
/pecl/phar phar_object.c
/pecl/phar/tests phar_copy.phpt phar_oo_compressed_001.phpt
phar_oo_compressed_001b.phpt
phar_oo_getcontentsgz.phpt
Log:
combine PharFileInfo->setCompressedGZ/setCompressedBZIP2 into compress() with
parameter Phar::GZ or Phar::BZ2
use ZEND_ACC_PUBLIC in PharFileInfo definitions, to be consistent
[DOC]
http://cvs.php.net/viewvc.cgi/pecl/phar/phar_object.c?r1=1.202&r2=1.203&diff_format=u
Index: pecl/phar/phar_object.c
diff -u pecl/phar/phar_object.c:1.202 pecl/phar/phar_object.c:1.203
--- pecl/phar/phar_object.c:1.202 Fri Apr 11 13:07:12 2008
+++ pecl/phar/phar_object.c Fri Apr 11 13:26:02 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: phar_object.c,v 1.202 2008/04/11 13:07:12 cellog Exp $ */
+/* $Id: phar_object.c,v 1.203 2008/04/11 13:26:02 cellog Exp $ */
#include "phar_internal.h"
#include "func_interceptors.h"
@@ -3305,7 +3305,7 @@
/* a number that is not Phar::GZ or Phar::BZ2 */
long method = 9021976;
PHAR_ENTRY_OBJECT();
-
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &method) ==
FAILURE) {
return;
}
@@ -3324,28 +3324,6 @@
}
/* }}} */
-/* {{{ proto bool PharFileInfo::isCompressedGZ()
- * Returns whether the entry is compressed using gz
- */
-PHP_METHOD(PharFileInfo, isCompressedGZ)
-{
- PHAR_ENTRY_OBJECT();
-
- RETURN_BOOL(entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ);
-}
-/* }}} */
-
-/* {{{ proto bool PharFileInfo::isCompressedBZIP2()
- * Returns whether the entry is compressed using bzip2
- */
-PHP_METHOD(PharFileInfo, isCompressedBZIP2)
-{
- PHAR_ENTRY_OBJECT();
-
- RETURN_BOOL(entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2);
-}
-/* }}} */
-
/* {{{ proto int PharFileInfo::getCRC32()
* Returns CRC32 code or throws an exception if not CRC checked
*/
@@ -3572,14 +3550,19 @@
}
/* }}} */
-/* {{{ proto int PharFileInfo::setCompressedGZ()
- * Instructs the Phar class to compress the current file using zlib
+/* {{{ proto int PharFileInfo::compress(int compression_type)
+ * Instructs the Phar class to compress the current file using zlib or bzip2
compression
*/
-PHP_METHOD(PharFileInfo, setCompressedGZ)
+PHP_METHOD(PharFileInfo, compress)
{
+ long method = 9021976;
char *error;
PHAR_ENTRY_OBJECT();
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method) ==
FAILURE) {
+ return;
+ }
+
if (entry_obj->ent.entry->is_tar) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0
TSRMLS_CC,
"Cannot compress with Gzip compression, not possible
with tar-based phar archives");
@@ -3590,10 +3573,6 @@
"Phar entry is a directory, cannot set compression"); \
return;
}
- if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ) {
- RETURN_TRUE;
- return;
- }
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");
@@ -3604,65 +3583,64 @@
"Cannot compress deleted file");
return;
}
- 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;
- }
- 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_GZ;
- entry_obj->ent.entry->phar->is_modified = 1;
- entry_obj->ent.entry->is_modified = 1;
- phar_flush(entry_obj->ent.entry->phar, 0, 0, 0, &error TSRMLS_CC);
- if (error) {
- zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC,
error);
- efree(error);
+ switch (method) {
+ case PHAR_ENT_COMPRESSED_GZ:
+ if (entry_obj->ent.entry->flags &
PHAR_ENT_COMPRESSED_GZ) {
+ RETURN_TRUE;
+ return;
+ }
+ if ((entry_obj->ent.entry->flags &
PHAR_ENT_COMPRESSED_BZ2) != 0) {
+ if (!phar_has_bz2) {
+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Cannot compress with gzip
compression, file is already compressed with bzip2 compression and bz2
extension is not enabled, cannot decompress");
+ return;
+ }
+ /* decompress this file indirectly */
+ if (SUCCESS !=
phar_open_entry_fp(entry_obj->ent.entry, &error TSRMLS_CC)) {
+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Phar error: Cannot decompress
bzip2-compressed file \"%s\" in phar \"%s\" in order to compress with gzip:
%s", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname, error);
+ efree(error);
+ return;
+ }
+ }
+ if ((entry_obj->ent.entry->flags &
PHAR_ENT_COMPRESSED_GZ) != 0 && !phar_has_zlib) {
+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Cannot compress with gzip compression,
zlib 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_GZ;
+ break;
+ case PHAR_ENT_COMPRESSED_BZ2:
+ if (entry_obj->ent.entry->flags &
PHAR_ENT_COMPRESSED_BZ2) {
+ RETURN_TRUE;
+ return;
+ }
+ if ((entry_obj->ent.entry->flags &
PHAR_ENT_COMPRESSED_GZ) != 0) {
+ if (!phar_has_zlib) {
+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Cannot compress with bzip2
compression, file is already compressed with gzip compression and zlib
extension is not enabled, cannot decompress");
+ return;
+ }
+ /* decompress this file indirectly */
+ if (SUCCESS !=
phar_open_entry_fp(entry_obj->ent.entry, &error TSRMLS_CC)) {
+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Phar error: Cannot decompress
gzip-compressed file \"%s\" in phar \"%s\" in order to compress with bzip2:
%s", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname, error);
+ efree(error);
+ 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;
+ break;
+ default:
+ zend_throw_exception_ex(spl_ce_BadMethodCallException,
0 TSRMLS_CC, \
+ "Unknown compression type specified"); \
}
- RETURN_TRUE;
-}
-/* }}} */
-/* {{{ proto int PharFileInfo::setCompressedBZIP2()
- * Instructs the Phar class to compress the current file using bzip2
- */
-PHP_METHOD(PharFileInfo, setCompressedBZIP2)
-{
- char *error;
- PHAR_ENTRY_OBJECT();
-
- 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");
- 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;
- }
- if (entry_obj->ent.entry->is_dir) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0
TSRMLS_CC, \
- "Phar entry is a directory, cannot set compression"); \
- return;
- }
- if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
- RETURN_TRUE;
- }
- 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;
- }
- if (entry_obj->ent.entry->is_deleted) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0
TSRMLS_CC,
- "Cannot compress deleted file");
- 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;
entry_obj->ent.entry->phar->is_modified = 1;
entry_obj->ent.entry->is_modified = 1;
@@ -3703,12 +3681,12 @@
"Cannot compress deleted file");
return;
}
- if (!phar_has_zlib) {
+ if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ) != 0 &&
!phar_has_zlib) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0
TSRMLS_CC,
"Cannot decompress Gzip-compressed file, zlib extension
is not enabled");
return;
}
- if (!phar_has_bz2) {
+ if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) != 0 &&
!phar_has_bz2) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0
TSRMLS_CC,
"Cannot decompress Bzip2-compressed file, bz2 extension
is not enabled");
return;
@@ -3802,6 +3780,11 @@
ZEND_END_ARG_INFO();
static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_compo, 0, 0, 0)
+ ZEND_ARG_INFO(0, compression_type)
+ZEND_END_ARG_INFO();
+
+static
ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_copy, 0, 0, 2)
ZEND_ARG_INFO(0, newfile)
ZEND_ARG_INFO(0, oldfile)
@@ -3942,22 +3925,21 @@
ZEND_END_ARG_INFO();
zend_function_entry php_entry_methods[] = {
- PHP_ME(PharFileInfo, __construct, arginfo_entry___construct, 0)
- PHP_ME(PharFileInfo, __destruct, NULL, 0)
- PHP_ME(PharFileInfo, chmod, arginfo_entry_chmod, 0)
- PHP_ME(PharFileInfo, delMetadata, NULL, 0)
- PHP_ME(PharFileInfo, getContent, NULL, 0)
- PHP_ME(PharFileInfo, getCompressedSize, NULL, 0)
- PHP_ME(PharFileInfo, getCRC32, NULL, 0)
- PHP_ME(PharFileInfo, getMetadata, NULL, 0)
- PHP_ME(PharFileInfo, getPharFlags, NULL, 0)
- PHP_ME(PharFileInfo, hasMetadata, NULL, 0)
- PHP_ME(PharFileInfo, isCompressed, arginfo_phar_comp, 0)
- PHP_ME(PharFileInfo, isCRCChecked, NULL, 0)
- PHP_ME(PharFileInfo, setCompressedBZIP2, NULL, 0)
- PHP_ME(PharFileInfo, setCompressedGZ, NULL, 0)
- PHP_ME(PharFileInfo, setMetadata, arginfo_phar_setMetadata, 0)
- PHP_ME(PharFileInfo, decompress, NULL, 0)
+ PHP_ME(PharFileInfo, __construct, arginfo_entry___construct,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, __destruct, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, chmod, arginfo_entry_chmod,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, delMetadata, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, getContent, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, getCompressedSize, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, getCRC32, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, getMetadata, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, getPharFlags, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, hasMetadata, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, isCompressed, arginfo_phar_compo,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, isCRCChecked, NULL,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, compress, arginfo_phar_comp,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, setMetadata, arginfo_phar_setMetadata,
ZEND_ACC_PUBLIC)
+ PHP_ME(PharFileInfo, decompress, NULL,
ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
#endif /* HAVE_SPL */
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_copy.phpt?r1=1.4&r2=1.5&diff_format=u
Index: pecl/phar/tests/phar_copy.phpt
diff -u pecl/phar/tests/phar_copy.phpt:1.4 pecl/phar/tests/phar_copy.phpt:1.5
--- pecl/phar/tests/phar_copy.phpt:1.4 Wed Jan 9 00:58:36 2008
+++ pecl/phar/tests/phar_copy.phpt Fri Apr 11 13:26:02 2008
@@ -25,7 +25,7 @@
$p->startBuffering();
$p->copy('a', 'b');
echo file_get_contents($p['b']->getPathName());
- $p['a']->setCompressedGZ();
+ $p['a']->compress(Phar::GZ);
$p['b']->setMetadata('a');
$p->copy('b', 'c');
$p->stopBuffering();
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_oo_compressed_001.phpt?r1=1.6&r2=1.7&diff_format=u
Index: pecl/phar/tests/phar_oo_compressed_001.phpt
diff -u pecl/phar/tests/phar_oo_compressed_001.phpt:1.6
pecl/phar/tests/phar_oo_compressed_001.phpt:1.7
--- pecl/phar/tests/phar_oo_compressed_001.phpt:1.6 Fri Apr 11 12:56:52 2008
+++ pecl/phar/tests/phar_oo_compressed_001.phpt Fri Apr 11 13:26:02 2008
@@ -1,5 +1,5 @@
--TEST--
-Phar::setCompressedGZ()
+Phar: PharFileInfo::compress(Phar::GZ)
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
<?php if (!extension_loaded("zlib")) die("skip zlib not present"); ?>
@@ -31,7 +31,7 @@
$phar['a'] = 'new a';
$phar['a']->decompress();
$phar['b'] = 'new b';
-$phar['b']->setCompressedGZ();
+$phar['b']->compress(Phar::GZ);
$phar['d'] = 'new d';
$phar = new Phar($fname);
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_oo_compressed_001b.phpt?r1=1.5&r2=1.6&diff_format=u
Index: pecl/phar/tests/phar_oo_compressed_001b.phpt
diff -u pecl/phar/tests/phar_oo_compressed_001b.phpt:1.5
pecl/phar/tests/phar_oo_compressed_001b.phpt:1.6
--- pecl/phar/tests/phar_oo_compressed_001b.phpt:1.5 Fri Apr 11 12:56:52 2008
+++ pecl/phar/tests/phar_oo_compressed_001b.phpt Fri Apr 11 13:26:02 2008
@@ -1,5 +1,5 @@
--TEST--
-Phar::setCompressedBZip2()
+Phar: PharFileInfo::compress(Phar::BZ2)
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
<?php if (!extension_loaded("bz2")) die("skip bz2 not present"); ?>
@@ -31,7 +31,7 @@
$phar['a'] = 'new a';
$phar['a']->decompress();
$phar['b'] = 'new b';
-$phar['b']->setCompressedBZip2();
+$phar['b']->compress(Phar::BZ2);
$phar['d'] = 'new d';
$phar = new Phar($fname);
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_oo_getcontentsgz.phpt?r1=1.2&r2=1.3&diff_format=u
Index: pecl/phar/tests/phar_oo_getcontentsgz.phpt
diff -u pecl/phar/tests/phar_oo_getcontentsgz.phpt:1.2
pecl/phar/tests/phar_oo_getcontentsgz.phpt:1.3
--- pecl/phar/tests/phar_oo_getcontentsgz.phpt:1.2 Thu Apr 10 13:41:28 2008
+++ pecl/phar/tests/phar_oo_getcontentsgz.phpt Fri Apr 11 13:26:02 2008
@@ -14,7 +14,7 @@
$phar = new Phar($fname);
$phar['a'] = 'file contents
this works';
-$phar['a']->setCompressedGZ();
+$phar['a']->compress(Phar::GZ);
copy($fname, $fname2);
$phar2 = new Phar($fname2);
var_dump($phar2['a']->isCompressed());