Skip to content

Commit 37585eb

Browse files
committed
use copy() instead of rename() on Windows
On Windows depending on the PHP version rename() can fail if the target file is being executed. Since the source file is not used by another process using copy() instead should be safe to be used.
1 parent e67bfc1 commit 37585eb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ private function write(string $file, string $data, ?int $expiresAt = null)
114114
touch($this->tmp, $expiresAt ?: time() + 31556952); // 1 year in seconds
115115
}
116116

117-
$success = rename($this->tmp, $file);
117+
if ('\\' === \DIRECTORY_SEPARATOR) {
118+
$success = copy($this->tmp, $file);
119+
} else {
120+
$success = rename($this->tmp, $file);
121+
}
122+
118123
$unlink = !$success;
119124

120125
return $success;

0 commit comments

Comments
 (0)