Skip to content

[Cache] FilesystemCommonTrait - rename fails on windows #50326

Closed
@lekoala

Description

@lekoala

Symfony version(s) affected

4.x > 6.x

Description

The rename function can fail on windows for some php versions

https://github.com/symfony/cache/blob/1ce7ed8e7ca6948892b6a3a52bb60cf2b04f7c94/Traits/FilesystemCommonTrait.php#LL107C17-L107C17

This is a current php issue here
php/php-src#7910

For context, I've found the issue while working with SilverStripe cache adapter (it's using cache version 4, but since it's an issue with the rename function, I suspect it's going to be the same for 5.x and 6.x)
silverstripe/silverstripe-framework#10634

I've also found that it has been an issue in composer that needed platform specific fix here
composer/composer#10446

How to reproduce

here is a demo here showing the issue

https://github.com/johnstevenson/php-rename-bug/actions/runs/1669358275

Possible Solution

Don't use rename function

replace with (for all, or only for windows using platform check)

$didCopy = copy($oldName, $newName, $context);

if (!$didCopy) {
    return false;
}

@unlink($oldName, $context);

return true;

Additional Context

Example error log
...\silverstripe-cache\...\configcache\U\F\QAdjY48zDlbAQWHpYUrw): Access is denied (code: 5) at ...\vendor\symfony\cache\Traits\FilesystemCommonTrait.php:115)"} []

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions