Skip to content

Commit

Permalink
[Filesystem] Check number of bytes copied.
Browse files Browse the repository at this point in the history
  • Loading branch information
skigun committed Sep 5, 2014
1 parent eb1e3c3 commit 81eca38
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -60,14 +60,18 @@ 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);

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);
}
}
}

Expand Down

0 comments on commit 81eca38

Please sign in to comment.