Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/Caching/ValueObject/Storage/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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("<?php declare(strict_types = 1);\n\nreturn %s;", $exported), null);
$copySuccess = @\copy($tmpPath, $filePath);
@\unlink($tmpPath);

if ($copySuccess) {
return;
}

if (\DIRECTORY_SEPARATOR === '/' || ! \file_exists($filePath)) {
throw new CachingException(\sprintf('Could not write data to cache file %s.', $filePath));
}
// Filesystem::dumpFile() writes atomically via a temporary file + rename,
// so no manual temp-file handling is needed on the Rector side
$this->filesystem->dumpFile(
$filePath,
\sprintf("<?php declare(strict_types = 1);\n\nreturn %s;", $exported)
);
}

public function clean(string $key): void
Expand Down
Loading