]> granicus.if.org Git - php/commitdiff
add test for delete in phar, we needed to check the deleted flag in case the new...
authorGreg Beaver <cellog@php.net>
Fri, 5 Jan 2007 02:04:07 +0000 (02:04 +0000)
committerGreg Beaver <cellog@php.net>
Fri, 5 Jan 2007 02:04:07 +0000 (02:04 +0000)
ext/phar/phar.c
ext/phar/tests/delete_in_phar.phpt [new file with mode: 0644]

index 912a5431ce1e7843c9893c8b55866e50480bf451..9c444c4bb7afd7940f272954a75d3c59b74244f6 100644 (file)
@@ -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 (file)
index 0000000..99bf0d6
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+Phar: delete a file within a .phar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$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===
+<?php
+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';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--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===