]> granicus.if.org Git - php/commitdiff
- Clean up on flush
authorMarcus Boerger <helly@php.net>
Sat, 27 Jan 2007 23:02:42 +0000 (23:02 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 27 Jan 2007 23:02:42 +0000 (23:02 +0000)
ext/phar/phar.c

index 5ca6b87d8e6f7ca116091ee73fad62126d341262..8999385c5cf00967a942f860770ea75e90815a49 100644 (file)
@@ -1710,6 +1710,18 @@ static inline void phar_set_16(char *buffer, int var) /* {{{ */
 #endif
 } /* }}} */
 
+static int phar_flush_clean_deleted_apply(void *data TSRMLS_DC) /* {{{ */
+{
+       phar_entry_info *entry = (phar_entry_info *)data;
+
+       if (entry->fp_refcount <= 0 && entry->is_deleted) {
+               return ZEND_HASH_APPLY_REMOVE;
+       } else {
+               return ZEND_HASH_APPLY_KEEP;
+       }
+}
+/* }}} */
+
 /**
  * Save phar contents to disk
  *
@@ -1805,7 +1817,12 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len TSRMLS_DC)
        }
        manifest_ftell = php_stream_tell(newfile);
        halt_offset = manifest_ftell;
-       
+
+       /* Check whether we can get rid of some of the deleted entries which are
+        * unused. However some might still be in use so even after this clean-up
+        * we need to skip entries marked is_deleted. */
+       zend_hash_apply(&archive->manifest, phar_flush_clean_deleted_apply TSRMLS_CC);
+
        /* compress as necessary, calculate crcs, manifest size, and file sizes */
        new_manifest_count = 0;
        offset = 0;