From: Greg Beaver Date: Thu, 8 May 2008 02:58:45 +0000 (+0000) Subject: fix handling of mounted entries when flushing in all phars, and of deleted entries... X-Git-Tag: RELEASE_2_0_0b1~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53e02373d046aa29a7723f4e97db1794f48d4181;p=php fix handling of mounted entries when flushing in all phars, and of deleted entries with open references in tar-based phars, do not extract mounted entries, add to test --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 411decb84e..cf84213265 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2208,7 +2208,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, php_stream_close(entry->cfp); entry->cfp = 0; } - if (entry->is_deleted) { + if (entry->is_deleted || entry->is_mounted) { /* remove this from the new phar */ continue; } @@ -2430,8 +2430,8 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, if (zend_hash_get_current_data(&phar->manifest, (void **)&entry) == FAILURE) { continue; } - if (entry->is_deleted) { - /* remove this from the new phar */ + if (entry->is_deleted || entry->is_mounted) { + /* remove this from the new phar if deleted, ignore if mounted */ continue; } if (entry->is_dir) { @@ -2493,7 +2493,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, if (zend_hash_get_current_data(&phar->manifest, (void **)&entry) == FAILURE) { continue; } - if (entry->is_deleted || entry->is_dir) { + if (entry->is_deleted || entry->is_dir || entry->is_mounted) { continue; } if (entry->cfp) { diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index ef59ba5e5e..1135df5760 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -491,6 +491,7 @@ carry_on: path_len = entry_len; goto carry_on2; } + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Mounting of %s to %s failed", path, actual); } /* }}} */ @@ -3505,6 +3506,10 @@ static int phar_extract_file(zend_bool overwrite, phar_entry_info *entry, char * char *fullpath, *slash; mode_t mode; + if (entry->is_mounted) { + /* silently ignore mounted entries */ + return SUCCESS; + } len = spprintf(&fullpath, 0, "%s/%s", dest, entry->filename); if (len >= MAXPATHLEN) { char *tmp; diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 343aea58ef..0f141bc0ae 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -438,8 +438,16 @@ int phar_tar_writeheaders(void *pDest, void *argument TSRMLS_DC) struct _phar_pass_tar_info *fp = (struct _phar_pass_tar_info *)argument; char padding[512]; + if (entry->is_mounted) { + return ZEND_HASH_APPLY_KEEP; + } if (entry->is_deleted) { - return ZEND_HASH_APPLY_REMOVE; + if (entry->fp_refcount <= 0) { + return ZEND_HASH_APPLY_REMOVE; + } else { + /* we can't delete this in-memory until it is closed */ + return ZEND_HASH_APPLY_KEEP; + } } memset((char *) &header, 0, sizeof(header)); diff --git a/ext/phar/tests/phar_extract.phpt b/ext/phar/tests/phar_extract.phpt index c46260b569..82e5f8d191 100644 --- a/ext/phar/tests/phar_extract.phpt +++ b/ext/phar/tests/phar_extract.phpt @@ -13,8 +13,10 @@ $a = new Phar($fname); $a['file1.txt'] = 'hi'; $a['file2.txt'] = 'hi2'; $a['subdir/ectory/file.txt'] = 'hi3'; +$a->mount($pname . '/mount', __FILE__); $a->addEmptyDir('one/level'); +$a->extractTo(dirname(__FILE__) . '/extract', 'mount'); $a->extractTo(dirname(__FILE__) . '/extract'); $out = array(); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract'), RecursiveIteratorIterator::CHILD_FIRST) as $p => $b) { @@ -117,7 +119,7 @@ string(3) "hi2" bool(false) Invalid argument, expected a filename (string) or array of filenames -Warning: Phar::extractTo() expects parameter 1 to be string, array given in %sphar_extract.php on line 34 +Warning: Phar::extractTo() expects parameter 1 to be string, array given in %sphar_extract.php on line %d Invalid argument, extraction path must be non-zero length Unable to use path "%soops" for extraction, it is a file, must be a directory Invalid argument, array of filenames to extract contains non-string value diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 816180f550..43f2a75997 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -520,6 +520,9 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */ entry = (phar_entry_info *)data; p = (struct _phar_zip_pass*) arg; + if (entry->is_mounted) { + return ZEND_HASH_APPLY_KEEP; + } if (entry->is_deleted) { if (entry->fp_refcount <= 0) { return ZEND_HASH_APPLY_REMOVE;