xref: /PHP-8.3/ext/phar/tests/tar/bug70417.phpt (revision 39131219)
1--TEST--
2Bug #70417 (PharData::compress() doesn't close temp file)
3--EXTENSIONS--
4phar
5zlib
6--SKIPIF--
7<?php
8
9exec('lsof -p ' . getmypid(), $out, $status);
10if ($status !== 0) {
11    die("skip lsof(8) not available");
12}
13if (!str_starts_with($out[0], 'COMMAND')) {
14    die("skip Might be a different lsof");
15}
16?>
17--FILE--
18<?php
19function countOpenFiles() {
20    exec('lsof -p ' . escapeshellarg(getmypid()) . ' 2> /dev/null', $out);  // Note: valgrind can produce false positives for /usr/bin/lsof
21    return count($out);
22}
23$filename = __DIR__ . '/bug70417.tar';
24@unlink("$filename.gz");
25$openFiles1 = countOpenFiles();
26$arch = new PharData($filename);
27$arch->addFromString('foo', 'bar');
28$arch->compress(Phar::GZ);
29unset($arch);
30$openFiles2 = countOpenFiles();
31var_dump($openFiles1 === $openFiles2);
32?>
33--CLEAN--
34<?php
35$filename = __DIR__ . '/bug70417.tar';
36@unlink($filename);
37@unlink("$filename.gz");
38?>
39--EXPECT--
40bool(true)
41