xref: /PHP-8.4/ext/phar/tests/bug79082.phpt (revision 74859783)
1--TEST--
2Phar: Bug #79082: Files added to tar with Phar::buildFromIterator have all-access permissions
3--EXTENSIONS--
4phar
5--SKIPIF--
6<?php
7if (defined("PHP_WINDOWS_VERSION_MAJOR")) die("skip not for Windows")
8?>
9--FILE--
10<?php
11umask(022);
12var_dump(decoct(umask()));
13chmod(__DIR__ . '/test79082/test79082-testfile', 0644);
14chmod(__DIR__ . '/test79082/test79082-testfile2', 0400);
15
16foreach([Phar::TAR => 'tar', Phar::ZIP => 'zip'] as $format => $ext) {
17    clearstatcache();
18    $phar = new PharData(__DIR__ . '/test79082.' . $ext, format: $format);
19    $phar->buildFromIterator(new \RecursiveDirectoryIterator(__DIR__ . '/test79082', \FilesystemIterator::SKIP_DOTS), __DIR__ . '/test79082');
20    $phar->extractTo(__DIR__);
21    var_dump(decoct(stat(__DIR__ . '/test79082-testfile')['mode']));
22    var_dump(decoct(stat(__DIR__ . '/test79082-testfile2')['mode']));
23    unlink(__DIR__ . '/test79082-testfile');
24    unlink(__DIR__ . '/test79082-testfile2');
25}
26foreach([Phar::TAR => 'tar', Phar::ZIP => 'zip'] as $format => $ext) {
27    clearstatcache();
28    $phar = new PharData(__DIR__ . '/test79082-d.' . $ext, format: $format);
29    $phar->buildFromDirectory(__DIR__ . '/test79082');
30    $phar->extractTo(__DIR__);
31    var_dump(decoct(stat(__DIR__ . '/test79082-testfile')['mode']));
32    var_dump(decoct(stat(__DIR__ . '/test79082-testfile2')['mode']));
33    unlink(__DIR__ . '/test79082-testfile');
34    unlink(__DIR__ . '/test79082-testfile2');
35}
36?>
37--CLEAN--
38<?php
39unlink(__DIR__ . '/test79082.tar');
40unlink(__DIR__ . '/test79082.zip');
41unlink(__DIR__ . '/test79082-d.tar');
42unlink(__DIR__ . '/test79082-d.zip');
43?>
44--EXPECT--
45string(2) "22"
46string(6) "100644"
47string(6) "100400"
48string(6) "100644"
49string(6) "100400"
50string(6) "100644"
51string(6) "100400"
52string(6) "100644"
53string(6) "100400"
54