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
25 changes: 22 additions & 3 deletions src/Caching/ValueObject/Storage/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,35 @@ 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);

@staabm staabm Sep 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might consider dropping your workarounds and use FileSystem::writeAtomic instead

nette/utils@cc0326d#diff-0e93d4e4e78af9e32c960e4a2b36d8339bb2c76fa8b84ba8fe7df03cd9d542fe

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that cover windows issue? The windows needs copy instead of rename.

@staabm staabm Sep 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a automated test should tell

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I noted in previous comment, that' need php < 8.1, and that's only after scoped build deployed, and even on scoped build, I am not sure if CI can setup UAC protected locations windows setup.

$copySuccess = @\copy($tmpPath, $filePath);
@\unlink($tmpPath);

if ($copySuccess) {
/**
* @see https://github.com/rectorphp/rector/issues/9876
*
* Try the atomic write first, as rename() also works on unaffected Windows PHP versions
*/
$renameSuccess = @\rename($tmpPath, $filePath);
if ($renameSuccess) {
return;
}

if (\DIRECTORY_SEPARATOR === '/' || ! \file_exists($filePath)) {
throw new CachingException(\sprintf('Could not write data to cache file %s.', $filePath));
}

/**
* @see https://github.com/rectorphp/rector/issues/8432
* @see https://github.com/php/php-src/issues/7910
*
* Fall back only on affected Windows PHP versions where rename() failed
*/
$copySuccess = @\copy($tmpPath, $filePath);
@\unlink($tmpPath);

if ($copySuccess) {
return;
}

throw new CachingException(\sprintf('Could not write data to cache file %s.', $filePath));
}

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