Skip to content

Commit 6cfef7e

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 6cfef7e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ 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);
118-
$unlink = !$success;
117+
if ('\\' === \DIRECTORY_SEPARATOR) {
118+
$success = copy($this->tmp, $file);
119+
$unlink = true;
120+
} else {
121+
$success = rename($this->tmp, $file);
122+
$unlink = !$success;
123+
}
119124

120125
return $success;
121126
} finally {

0 commit comments

Comments
 (0)