Skip to content

Commit d79a32d

Browse files
authored
run-tests: Clean the file cache directory in --file-cache-prime (#22784)
`run-tests.php --file-cache-prime` sets opcache.file_cache to /tmp which makes it difficult to clear the cache. Set opcache.file_cache to /tmp/php-run-tests-file-cache, and clear the directory when --file-cache-prime is specified.
1 parent c191020 commit d79a32d

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

run-tests.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,32 @@ function find_files(string $dir, bool $is_ext_dir = false, bool $ignore = false)
10541054
closedir($o);
10551055
}
10561056

1057+
function rmdir_recursive($dir)
1058+
{
1059+
if (!file_exists($dir)) {
1060+
return;
1061+
}
1062+
if (!is_dir($dir)) {
1063+
unlink($dir);
1064+
return;
1065+
}
1066+
1067+
$dh = opendir($dir);
1068+
if (!$dh) {
1069+
return;
1070+
}
1071+
1072+
while (($entry = readdir($dh)) !== false) {
1073+
if ($entry === '.' || $entry === '..') {
1074+
continue;
1075+
}
1076+
rmdir_recursive($dir . DIRECTORY_SEPARATOR . $entry);
1077+
}
1078+
1079+
closedir($dh);
1080+
rmdir($dir);
1081+
}
1082+
10571083
/**
10581084
* @param array|string $name
10591085
*/
@@ -2065,7 +2091,11 @@ function run_test(string $php, $file, array $env): string
20652091
$orig_ini_settings = settings2params($ini_settings);
20662092

20672093
if ($file_cache !== null) {
2068-
$ini_settings['opcache.file_cache'] = '/tmp';
2094+
$ini_settings['opcache.file_cache'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-run-tests-file-cache';
2095+
if ($file_cache === 'prime') {
2096+
rmdir_recursive($ini_settings['opcache.file_cache']);
2097+
mkdir($ini_settings['opcache.file_cache'], recursive: true);
2098+
}
20692099
// Make sure warnings still show up on the second run.
20702100
$ini_settings['opcache.record_warnings'] = '1';
20712101
// File cache is currently incompatible with JIT.

0 commit comments

Comments
 (0)