]> granicus.if.org Git - php/commitdiff
fix handling of mounted entries when flushing in all phars, and of deleted entries...
authorGreg Beaver <cellog@php.net>
Thu, 8 May 2008 02:58:45 +0000 (02:58 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 8 May 2008 02:58:45 +0000 (02:58 +0000)
ext/phar/phar.c
ext/phar/phar_object.c
ext/phar/tar.c
ext/phar/tests/phar_extract.phpt
ext/phar/zip.c

index 411decb84eaf9384a8f43c442cb7c4c2a9348f14..cf84213265c3d38074aadb9a73bebf45b183c017 100644 (file)
@@ -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) {
index ef59ba5e5ee18166a620727cad57da0dcd0325cf..1135df5760eaba6b19bdda02579bdf677dbad729 100755 (executable)
@@ -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;
index 343aea58ef7774a6409abfddad4ac31b728c2c03..0f141bc0ae8a4b438323377282fed6e24d875a31 100644 (file)
@@ -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));
index c46260b56976989bc9d279193357d9991d92bf8f..82e5f8d1918e8d4624b6c05c3e49f19131f24606 100644 (file)
@@ -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
index 816180f550b0bb6c24f4081c4af8ddbabdd3ec18..43f2a7599738f83107fad6d7e7e640491d1b0d8d 100644 (file)
@@ -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;