merged branch stloyd/patch-3 (PR #7869)

This PR was merged into the 2.1 branch.

Discussion
----------

[Filesystem] copy() is not working when open_basedir is set

More details: https://bugs.php.net/bug.php?id=64634

Commits
-------

10dea94 [Filesystem] copy() is not working when open_basedir is set
This commit is contained in:
Fabien Potencier 2013-04-30 19:08:19 +02:00
commit ca4fb5530e

View File

@ -35,6 +35,10 @@ class Filesystem
*/
public function copy($originFile, $targetFile, $override = false)
{
if (!is_file($originFile)) {
throw new IOException(sprintf('Failed to copy %s because file not exists', $originFile));
}
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile)) {
@ -44,7 +48,15 @@ class Filesystem
}
if ($doCopy) {
if (true !== @copy($originFile, $targetFile)) {
// https://bugs.php.net/bug.php?id=64634
$source = fopen($originFile, 'r');
$target = fopen($targetFile, 'w+');
stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile));
}
}