cvs: pecl /phar TODO package.php phar_internal.h phar_object.c /phar/tests delete.phpt

From: Date: Sat, 25 Aug 2007 01:32:34 +0000
Subject: cvs: pecl /phar TODO package.php phar_internal.h phar_object.c /phar/tests delete.phpt
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-8474@lists.php.net to get a copy of this message
cellog Sat Aug 25 01:32:34 2007 UTC Added files: /pecl/phar/tests delete.phpt Modified files: /pecl/phar TODO package.php phar_internal.h phar_object.c Log: move to 1.3.0 development add Phar::delete() http://cvs.php.net/viewvc.cgi/pecl/phar/TODO?r1=1.43&r2=1.44&diff_format=u Index: pecl/phar/TODO diff -u pecl/phar/TODO:1.43 pecl/phar/TODO:1.44 --- pecl/phar/TODO:1.43 Thu Aug 23 04:49:38 2007 +++ pecl/phar/TODO Sat Aug 25 01:32:34 2007 @@ -69,7 +69,7 @@ * ability to match files containing a metadata key opendir('phar://a.phar/?mime-type=image/jpeg') or foreach ($p->match('mime-type', 'image/jpeg') as $file) * Phar::copy($from, $to); - * Phar::delete($what) + X Phar::delete($what) [Greg] * Phar::buildFromIterator($filename, Iterator $it, array $addinfo = null); $addinfo = array('alias','flags','metadata','stub'...) * Layout: Option to compress all content rather than single files. http://cvs.php.net/viewvc.cgi/pecl/phar/package.php?r1=1.20&r2=1.21&diff_format=u Index: pecl/phar/package.php diff -u pecl/phar/package.php:1.20 pecl/phar/package.php:1.21 --- pecl/phar/package.php:1.20 Thu Aug 23 04:49:38 2007 +++ pecl/phar/package.php Sat Aug 25 01:32:34 2007 @@ -1,18 +1,7 @@ <?php $notes = ' - * add Phar::setAlias() [Greg] - * fix too many open file handles issue [Greg] - * fix rename [Greg] - * add Phar::getAlias() [Marcus] - * Made -a optional in pack subcommand of phar.phar [Marcus] - * Fix issue with apache module and extracted archives [Marcus] - * Send all error messages to stderr in phar.phar [Marcus] - * Added new subcommands add and delete to phar.phar [Marcus] - * Made Phar::loadPhar() and Phar::mapPhar() ignore extracted archives [Marcus] - * Fix issue with compressed entries and uncompressing entries [Marcus] - * Verify stubs before writing [Marcus] - * Always use longest stub end to avoid issues with length field [Marcus] + * add Phar::delete() [Greg] '; if (!class_exists("Phar") && !extension_loaded("Phar")) { http://cvs.php.net/viewvc.cgi/pecl/phar/phar_internal.h?r1=1.36&r2=1.37&diff_format=u Index: pecl/phar/phar_internal.h diff -u pecl/phar/phar_internal.h:1.36 pecl/phar/phar_internal.h:1.37 --- pecl/phar/phar_internal.h:1.36 Fri Aug 17 04:47:49 2007 +++ pecl/phar/phar_internal.h Sat Aug 25 01:32:34 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_internal.h,v 1.36 2007/08/17 04:47:49 cellog Exp $ */ +/* $Id: phar_internal.h,v 1.37 2007/08/25 01:32:34 cellog Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -62,7 +62,7 @@ #define E_RECOVERABLE_ERROR E_ERROR #endif -#define PHAR_EXT_VERSION_STR "1.2.1" +#define PHAR_EXT_VERSION_STR "1.3.0" #define PHAR_API_VERSION_STR "1.1.0" /* x.y.z maps to 0xyz0 */ #define PHAR_API_VERSION 0x1100 http://cvs.php.net/viewvc.cgi/pecl/phar/phar_object.c?r1=1.60&r2=1.61&diff_format=u Index: pecl/phar/phar_object.c diff -u pecl/phar/phar_object.c:1.60 pecl/phar/phar_object.c:1.61 --- pecl/phar/phar_object.c:1.60 Thu Aug 23 23:23:25 2007 +++ pecl/phar/phar_object.c Sat Aug 25 01:32:34 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_object.c,v 1.60 2007/08/23 23:23:25 cellog Exp $ */ +/* $Id: phar_object.c,v 1.61 2007/08/25 01:32:34 cellog Exp $ */ #include "phar_internal.h" @@ -287,6 +287,51 @@ } /* }}} */ +/* {{{ proto bool Phar::delete(string file) + * Delete a file from within the Phar + */ +PHP_METHOD(Phar, delete) +{ + char *fname; + int fname_len; + char *error; + phar_entry_info *entry; + PHAR_ARCHIVE_OBJECT(); + + if (PHAR_G(readonly)) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "Cannot write out phar archive, phar is read-only"); + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { + RETURN_FALSE; + } + + if (zend_hash_exists(&phar_obj->arc.archive->manifest, fname, (uint) fname_len)) { + if (SUCCESS == zend_hash_find(&phar_obj->arc.archive->manifest, fname, (uint) fname_len, (void**)&entry)) { + if (entry->is_deleted) { + /* entry is deleted, but has not been flushed to disk yet */ + RETURN_TRUE; + } else { + entry->is_deleted = 1; + entry->is_modified = 1; + phar_obj->arc.archive->is_modified = 1; + } + } + } else { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Entry %s does not exist and cannot be deleted", fname); + RETURN_FALSE; + } + + phar_flush(phar_obj->arc.archive, NULL, 0, &error TSRMLS_CC); + if (error) { + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error); + efree(error); + } + + RETURN_TRUE; +} + /* {{{ proto int Phar::getAlias() * Returns the alias for the PHAR or NULL */ @@ -309,6 +354,12 @@ phar_archive_data *fd, **fd_ptr; int alias_len; PHAR_ARCHIVE_OBJECT(); + + if (PHAR_G(readonly)) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "Cannot write out phar archive, phar is read-only"); + } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &alias, &alias_len) == SUCCESS) { if (alias_len == phar_obj->arc.archive->alias_len && memcmp(phar_obj->arc.archive->alias, alias, alias_len) == 0) { RETURN_TRUE; @@ -1450,6 +1501,7 @@ PHP_ME(Phar, compressAllFilesGZ, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, compressAllFilesBZIP2, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, count, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phar, delete, arginfo_phar_mapPhar, ZEND_ACC_PUBLIC) PHP_ME(Phar, delMetadata, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, getAlias, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, getMetadata, NULL, ZEND_ACC_PUBLIC) http://cvs.php.net/viewvc.cgi/pecl/phar/tests/delete.phpt?view=markup&rev=1.1 Index: pecl/phar/tests/delete.phpt +++ pecl/phar/tests/delete.phpt --TEST-- Phar: delete test --SKIPIF-- <?php if (!extension_loaded("phar")) print "skip"; ?> --INI-- phar.readonly=0 phar.require_hash=0 --FILE-- <?php $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; $pname = 'phar://' . $fname; $file = "<?php Phar::mapPhar('hio'); __HALT_COMPILER(); ?>"; $files = array(); $files['a'] = 'a'; include 'phar_test.inc'; include $fname; $phar = new Phar($fname); echo file_get_contents($pname . '/a') . "\n"; $phar->delete('a'); echo file_get_contents($pname . '/a') . "\n"; ?> --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> --EXPECTF-- a Warning: file_get_contents(phar://%sdelete.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.php" in %sdelete.php on line 16

« previous php.pecl.cvs (#8474) next »