xref: /PHP-8.1/ext/phar/tests/phar_extract2.phpt (revision 74859783)
1--TEST--
2Phar: Phar::extractTo() - .phar safety
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9
10$fname = __DIR__ . '/tempmanifest2.phar.php';
11$pname = 'phar://' . $fname;
12
13$phar = new Phar($fname);
14$phar->setDefaultStub();
15$phar->setAlias('fred');
16$phar['file1.txt'] = 'hi';
17$phar['file2.txt'] = 'hi2';
18$phar['subdir/ectory/file.txt'] = 'hi3';
19$phar->mount($pname . '/mount2', __FILE__);
20$phar->addEmptyDir('one/level');
21
22$phar->extractTo(__DIR__ . '/extract2', 'mount2');
23$phar->extractTo(__DIR__ . '/extract2');
24$out = array();
25
26foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/extract2', 0x00003000), RecursiveIteratorIterator::CHILD_FIRST) as $path => $file) {
27    $extracted[] = $path;
28}
29
30sort($extracted);
31
32foreach ($extracted as $out) {
33    echo "$out\n";
34}
35
36?>
37--CLEAN--
38<?php
39@unlink(__DIR__ . '/tempmanifest2.phar.php');
40$dir = __DIR__ . '/extract2/';
41@unlink($dir . 'file1.txt');
42@unlink($dir . 'file2.txt');
43@unlink($dir . 'subdir/ectory/file.txt');
44@rmdir($dir . 'subdir/ectory');
45@rmdir($dir . 'subdir');
46@rmdir($dir . 'one/level');
47@rmdir($dir . 'one');
48@rmdir($dir);
49$dir = __DIR__ . '/extract1/';
50@rmdir($dir);
51?>
52--EXPECTF--
53%sextract2%cfile1.txt
54%sextract2%cfile2.txt
55%sextract2%cone
56%sextract2%csubdir
57%sextract2%csubdir%cectory
58%sextract2%csubdir%cectory%cfile.txt
59