From: Marcus Boerger Date: Sat, 27 Jan 2007 23:02:42 +0000 (+0000) Subject: - Clean up on flush X-Git-Tag: RELEASE_1_0_0RC1~106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b2eed1fc187138aaea01213a7e1a2fd281dd2c2;p=php - Clean up on flush --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 5ca6b87d8e..8999385c5c 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -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;