From: Greg Beaver Date: Fri, 5 Jan 2007 02:04:07 +0000 (+0000) Subject: add test for delete in phar, we needed to check the deleted flag in case the new... X-Git-Tag: RELEASE_1_0_0RC1~398 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7c42d9d47f8de2db27e094b721f8ab5df8f790b;p=php add test for delete in phar, we needed to check the deleted flag in case the new phar has not been flushed to disk --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 912a5431ce..9c444c4bb7 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -320,6 +320,10 @@ static phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, return NULL; } if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) { + if (entry->flags & PHAR_ENT_DELETED) { + /* entry is deleted, but has not been flushed to disk yet */ + return NULL; + } return entry; } return NULL; diff --git a/ext/phar/tests/delete_in_phar.phpt b/ext/phar/tests/delete_in_phar.phpt new file mode 100644 index 0000000000..99bf0d66d0 --- /dev/null +++ b/ext/phar/tests/delete_in_phar.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar: delete a file within a .phar +--SKIPIF-- + +--FILE-- +"; + +$files = array(); +$files['a.php'] = ''; +$files['b.php'] = ''; +$files['b/c.php'] = ''; +$manifest = ''; +foreach($files as $name => $cont) { + $len = strlen($cont); + $manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00); +} +$alias = ''; +$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest; +$file .= pack('V', strlen($manifest)) . $manifest; +foreach($files as $cont) +{ + $file .= $cont; +} + +file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file); + +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/a.php'; +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b.php'; +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; +unlink('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'); +?> +===AFTER=== + + +===DONE=== +--CLEAN-- + +--EXPECTF-- +This is a +This is b +This is b/c +===AFTER=== +This is a +This is b +Warning: include(%selete_in_phar.phpt.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%selete_in_phar.phpt.phar.php" in %selete_in_phar.phpt on line %d +===DONE===