xref: /PHP-5.4/ext/phar/tests/tar/refcount1.phpt (revision 377ff97a)
1--TEST--
2Phar: test that refcounting avoids problems with deleting a file tar-based
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6<?php if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later"); ?>
7--INI--
8phar.readonly=0
9phar.require_hash=0
10--FILE--
11<?php
12include dirname(__FILE__) . '/files/tarmaker.php.inc';
13$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
14$alias = 'phar://' . $fname;
15
16$tar = new tarmaker($fname, 'none');
17$tar->init();
18$tar->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>");
19
20$files = array();
21
22$files['a.php'] = '<?php echo "This is a\n"; ?>';
23$files['b.php'] = '<?php echo "This is b\n"; ?>';
24$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
25$files['.phar/alias.txt'] = 'hio';
26
27foreach ($files as $n => $file) {
28	$tar->addFile($n, $file);
29}
30
31$tar->close();
32
33$fp = fopen($alias . '/b/c.php', 'wb');
34fwrite($fp, b"extra");
35fclose($fp);
36echo "===CLOSE===\n";
37$phar = new Phar($fname);
38$b = fopen($alias . '/b/c.php', 'rb');
39$a = $phar['b/c.php'];
40var_dump($a);
41var_dump(fread($b, 20));
42rewind($b);
43echo "===UNLINK===\n";
44unlink($alias . '/b/c.php');
45var_dump($a);
46var_dump(fread($b, 20));
47include $alias . '/b/c.php';
48
49?>
50
51===DONE===
52--CLEAN--
53<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
54--EXPECTF--
55===CLOSE===
56object(PharFileInfo)#%d (2) {
57  [%spathName":%sSplFileInfo":private]=>
58  string(%d) "phar://%srefcount1.phar.tar/b/c.php"
59  [%sfileName":%sSplFileInfo":private]=>
60  string(%d) "c.php"
61}
62string(5) "extra"
63===UNLINK===
64
65Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.tar", has open file pointers, cannot unlink in %srefcount1.php on line %d
66object(PharFileInfo)#%d (2) {
67  [%spathName":%sSplFileInfo":private]=>
68  string(%d) "phar://%srefcount1.phar.tar/b/c.php"
69  [%sfileName":%sSplFileInfo":private]=>
70  string(%s) "c.php"
71}
72string(5) "extra"
73extra
74===DONE===
75