Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b437362

Browse files
bug #57663 [Cache] use copy() instead of rename() on Windows (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [Cache] use copy() instead of rename() on Windows | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #50326 | License | MIT 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. Commits ------- 6cfef7e use copy() instead of rename() on Windows
2 parents 737d519 + 6cfef7e commit b437362

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)