diff --git a/src/Analyser/Parallel/ParallelAnalysisNodeExtractor.php b/src/Analyser/Parallel/ParallelAnalysisNodeExtractor.php index b7a10ec3..2b0e9432 100644 --- a/src/Analyser/Parallel/ParallelAnalysisNodeExtractor.php +++ b/src/Analyser/Parallel/ParallelAnalysisNodeExtractor.php @@ -13,7 +13,6 @@ use Boundwize\StructArmed\Cache\AnalysisResultCache; use Boundwize\StructArmed\Cache\CachePathFactory; use Boundwize\StructArmed\Progress\ProgressHandlerInterface; -use FilesystemIterator; use RuntimeException; use function array_fill; @@ -336,13 +335,11 @@ public function extract( } } - // when --no-cache is used and no files in the cache directory yet, remove dir cache - // as means only for temporary file for worker needs + // when --no-cache is used, the directory only held worker temporary files: + // remove it best-effort, rmdir() refuses a non-empty directory atomically, + // so a concurrent run's files or an existing cache keep it in place if (! $this->analysisResultCache instanceof AnalysisResultCache) { - $fileSystemIterator = new FilesystemIterator($cacheDirectory); - if (! $fileSystemIterator->valid()) { - rmdir($cacheDirectory); - } + @rmdir($cacheDirectory); } if ($failures !== []) { diff --git a/src/Cache/AnalysisResultCache.php b/src/Cache/AnalysisResultCache.php index dd15a30e..6578bd94 100644 --- a/src/Cache/AnalysisResultCache.php +++ b/src/Cache/AnalysisResultCache.php @@ -17,7 +17,6 @@ use Boundwize\StructArmed\Composer\ComposerJsonProvider; use Boundwize\StructArmed\Rule\RuleViolation; use Boundwize\StructArmed\Rule\RuleViolationCollection; -use FilesystemIterator; use function array_fill_keys; use function array_is_list; @@ -177,11 +176,9 @@ public function clear(): void } } - // only remove the cache directory if it is empty - $fileSystemIterator = new FilesystemIterator($this->cacheDirectory); - if (! $fileSystemIterator->valid()) { - rmdir($this->cacheDirectory); - } + // only remove the cache directory if it is empty: rmdir() refuses a + // non-empty directory atomically, so a concurrent run's files keep it + @rmdir($this->cacheDirectory); } public function getCacheDirectory(): string