From ec6bb90933ed4ab0dcb826d5831cf6ffbaeb3ff5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 6 Aug 2026 15:18:53 +0000 Subject: [PATCH] Simplify FileCacheStorage::save() with atomic dumpFile() Replace the manual temp-file + copy + unlink handling with Symfony's Filesystem::dumpFile(), which already writes atomically via a temporary file and rename internally. Finishes the cleanup started in #498 that had since regressed. Drops the now-unused Nette\Utils\Random import. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Ti6vHRo3xLSHw84rxUw6Lb --- .../ValueObject/Storage/FileCacheStorage.php | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Caching/ValueObject/Storage/FileCacheStorage.php b/src/Caching/ValueObject/Storage/FileCacheStorage.php index b883cb4b9ae..3a7a31cbb40 100644 --- a/src/Caching/ValueObject/Storage/FileCacheStorage.php +++ b/src/Caching/ValueObject/Storage/FileCacheStorage.php @@ -6,7 +6,6 @@ use FilesystemIterator; use Nette\Utils\FileSystem; -use Nette\Utils\Random; use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; use Rector\Caching\ValueObject\CacheFilePaths; use Rector\Caching\ValueObject\CacheItem; @@ -55,7 +54,6 @@ public function save(string $key, string $variableKey, mixed $data): void $filePath = $cacheFilePaths->getFilePath(); - $tmpPath = \sprintf('%s/%s.tmp', $this->directory, Random::generate()); $errorBefore = \error_get_last(); $exported = @\var_export(new CacheItem($variableKey, $data), true); $errorAfter = \error_get_last(); @@ -68,18 +66,12 @@ public function save(string $key, string $variableKey, mixed $data): void )); } - // for performance reasons we don't use SmartFileSystem - FileSystem::write($tmpPath, \sprintf("filesystem->dumpFile( + $filePath, + \sprintf("