summaryrefslogtreecommitdiff
path: root/ext/phar/phar_object.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/phar/phar_object.c')
-rwxr-xr-xext/phar/phar_object.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 124c471a87..29f951389e 100755
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -287,6 +287,51 @@ PHP_METHOD(Phar, count)
}
/* }}} */
+/* {{{ 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 @@ PHP_METHOD(Phar, setAlias)
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 @@ zend_function_entry php_archive_methods[] = {
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)