From 81eca38d5a73e5be5339755ef6770a03df89d284 Mon Sep 17 00:00:00 2001 From: bertillon Date: Fri, 5 Sep 2014 11:25:44 +0200 Subject: [PATCH] [Filesystem] Check number of bytes copied. --- src/Symfony/Component/Filesystem/Filesystem.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 407344c3b437..d47115ed2695 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -60,7 +60,7 @@ public function copy($originFile, $targetFile, $override = false) throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile); } - stream_copy_to_stream($source, $target); + $bytesCopied = stream_copy_to_stream($source, $target); fclose($source); fclose($target); unset($source, $target); @@ -68,6 +68,10 @@ public function copy($originFile, $targetFile, $override = false) if (!is_file($targetFile)) { throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile); } + + if (stream_is_local($originFile) && $bytesCopied !== filesize($originFile)) { + throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s %g bytes copied".', $originFile, $targetFile, $bytesCopied), 0, null, $originFile); + } } }