bug #23092 [Filesystem] added workaround in Filesystem::rename for PHP bug (VolCh)

This PR was squashed before being merged into the 2.7 branch (closes #23092).

Discussion
----------

[Filesystem] added workaround in Filesystem::rename for PHP bug

[Filesystem] added workaround in Filesystem::rename for https://bugs.php.net/bug.php?id=54097

Standard PHP rename() of dirs across devices/mounted filesystems  produces confusing copy error & throws IOException in Filesystem::rename. I got it during console cache:clear  in the Docker environment. This PR possible fixes https://github.com/symfony/symfony/issues/19851 and other environment related issues.

Workaround is on \rename() fails try to Filesystem::mirror & Filesystem::remove if $origin is directory

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

3ccbc479da [Filesystem] added workaround in Filesystem::rename for PHP bug
This commit is contained in:
Fabien Potencier 2017-06-14 12:55:44 -07:00
commit d44f143c75
1 changed files with 7 additions and 0 deletions

View File

@ -276,6 +276,13 @@ class Filesystem
}
if (true !== @rename($origin, $target)) {
if (is_dir($origin)) {
// See https://bugs.php.net/bug.php?id=54097 & http://php.net/manual/en/function.rename.php#113943
$this->mirror($origin, $target, null, array('override' => $overwrite, 'delete' => $overwrite));
$this->remove($origin);
return;
}
throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target);
}
}