mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
fix race conditions causing notices if directory does not exist
This commit is contained in:
parent
cac9ec957c
commit
bb760a2224
@ -52,6 +52,7 @@ use function assert;
|
||||
use function basename;
|
||||
use function chdir;
|
||||
use function class_exists;
|
||||
use function clearstatcache;
|
||||
use function count;
|
||||
use function dirname;
|
||||
use function error_log;
|
||||
@ -2268,6 +2269,7 @@ class Config
|
||||
|
||||
public static function removeCacheDirectory(string $dir): void
|
||||
{
|
||||
clearstatcache(true, $dir);
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir, SCANDIR_SORT_NONE);
|
||||
|
||||
@ -2276,17 +2278,29 @@ class Config
|
||||
}
|
||||
|
||||
foreach ($objects as $object) {
|
||||
if ($object !== '.' && $object !== '..') {
|
||||
if (filetype($dir . '/' . $object) === 'dir') {
|
||||
self::removeCacheDirectory($dir . '/' . $object);
|
||||
} else {
|
||||
unlink($dir . '/' . $object);
|
||||
}
|
||||
if ($object === '.' || $object === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if it was deleted in the meantime/race condition with other psalm process
|
||||
if (!file_exists($dir . '/' . $object)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filetype($dir . '/' . $object) === 'dir') {
|
||||
self::removeCacheDirectory($dir . '/' . $object);
|
||||
} else {
|
||||
unlink($dir . '/' . $object);
|
||||
}
|
||||
}
|
||||
|
||||
reset($objects);
|
||||
rmdir($dir);
|
||||
|
||||
// may have been removed in the meantime
|
||||
clearstatcache(true, $dir);
|
||||
if (is_dir($dir)) {
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ use PhpParser\Node\Stmt;
|
||||
use Psalm\Config;
|
||||
use RuntimeException;
|
||||
|
||||
use function clearstatcache;
|
||||
use function error_log;
|
||||
use function fclose;
|
||||
use function file_get_contents;
|
||||
@ -302,6 +303,13 @@ class ParserCacheProvider
|
||||
return;
|
||||
}
|
||||
|
||||
// directory was removed
|
||||
// most likely due to a race condition with other psalm instances that were manually started at the same time
|
||||
clearstatcache(true, $root_cache_directory);
|
||||
if (!is_dir($root_cache_directory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file_content_hashes = $this->new_file_content_hashes + $this->getExistingFileContentHashes();
|
||||
|
||||
$file_hashes_path = $root_cache_directory . DIRECTORY_SEPARATOR . self::FILE_HASHES;
|
||||
|
Loading…
Reference in New Issue
Block a user