From 9d35e3c251ece7e0352e353ae2c1241433d02137 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 1 Nov 2020 09:01:43 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20#4464=20-=20bust=20cache=20when=20Psalm?= =?UTF-8?q?=E2=80=99s=20version=20changes,=20not=20just=20composer?= =?UTF-8?q?=E2=80=99s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 4 ++-- src/Psalm/Internal/Provider/ProjectCacheProvider.php | 12 ++++++++---- src/Psalm/IssueBuffer.php | 2 +- tests/Internal/Provider/ProjectCacheProvider.php | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 32477cc8e..6268966eb 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -640,7 +640,7 @@ class ProjectAnalyzer if ($this->project_cache_provider && $this->parser_cache_provider) { $removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches( - $is_diff ? $this->project_cache_provider->getLastRun() : $start_checks + $is_diff ? $this->project_cache_provider->getLastRun(\PSALM_VERSION) : $start_checks ); if ($removed_parser_files) { @@ -1069,7 +1069,7 @@ class ProjectAnalyzer $diff_files = []; - $last_run = $this->project_cache_provider->getLastRun(); + $last_run = $this->project_cache_provider->getLastRun(\PSALM_VERSION); $file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions); diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index cae6172e2..3cfcbfb63 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -40,7 +40,7 @@ class ProjectCacheProvider return $cache_directory && file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME); } - public function processSuccessfulRun(float $start_time): void + public function processSuccessfulRun(float $start_time, string $psalm_version): void { $cache_directory = Config::getInstance()->getCacheDirectory(); @@ -50,16 +50,20 @@ class ProjectCacheProvider $run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME; + file_put_contents($run_cache_location, $psalm_version); + \touch($run_cache_location, (int)$start_time); } - public function getLastRun(): int + public function getLastRun(string $psalm_version): int { if ($this->last_run === null) { $cache_directory = Config::getInstance()->getCacheDirectory(); - if (file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME)) { - $this->last_run = \filemtime($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME); + $run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME; + + if (file_exists($run_cache_location) && file_get_contents($run_cache_location) === $psalm_version) { + $this->last_run = \filemtime($run_cache_location); } else { $this->last_run = 0; } diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 741a2a71a..ea458cc50 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -669,7 +669,7 @@ class IssueBuffer $codebase->file_reference_provider->removeDeletedFilesFromReferences(); if ($project_analyzer->project_cache_provider) { - $project_analyzer->project_cache_provider->processSuccessfulRun($start_time); + $project_analyzer->project_cache_provider->processSuccessfulRun($start_time, \PSALM_VERSION); } if ($codebase->statements_provider->parser_cache_provider) { diff --git a/tests/Internal/Provider/ProjectCacheProvider.php b/tests/Internal/Provider/ProjectCacheProvider.php index 6117102a7..eaf54b317 100644 --- a/tests/Internal/Provider/ProjectCacheProvider.php +++ b/tests/Internal/Provider/ProjectCacheProvider.php @@ -12,12 +12,12 @@ class ProjectCacheProvider extends \Psalm\Internal\Provider\ProjectCacheProvider { } - public function getLastRun(): int + public function getLastRun(string $psalm_version): int { return $this->last_run; } - public function processSuccessfulRun(float $start_time): void + public function processSuccessfulRun(float $start_time, string $psalm_version): void { $this->last_run = (int) $start_time; }