From 68b54b4d83d503e5fb77ef432b0db67ac9bb0cb2 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sun, 7 Jan 2007 18:51:39 +0000 Subject: [PATCH] add test to make sure the phar is modified on disk --- ext/phar/tests/delete_in_phar_confirm.phpt | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ext/phar/tests/delete_in_phar_confirm.phpt diff --git a/ext/phar/tests/delete_in_phar_confirm.phpt b/ext/phar/tests/delete_in_phar_confirm.phpt new file mode 100644 index 0000000000..d4a4006a3e --- /dev/null +++ b/ext/phar/tests/delete_in_phar_confirm.phpt @@ -0,0 +1,62 @@ +--TEST-- +Phar: delete a file within a .phar +--SKIPIF-- + +--INI-- +phar.readonly=0 +--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'; +$md5 = md5_file(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'); +unlink('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'); +clearstatcache(); +$md52 = md5_file(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'); +if ($md5 == $md52) echo 'file was not modified'; +?> +===AFTER=== + + +===DONE=== +--CLEAN-- + +--EXPECTF-- +This is a +This is b +This is b/c +===AFTER=== +This is a +This is b + +Warning: include(%sdelete_in_phar.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.php" in %sdelete_in_phar.php on line %d + +Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.php/b/c.php' for inclusion (include_path='.') in %sdelete_in_phar.php on line %d + +===DONE=== + \ No newline at end of file -- 2.50.1