summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-02-23 12:31:22 +0100
committerVincent Petry <pvince81@owncloud.com>2015-02-25 16:03:15 +0100
commit20738d287e456ddb05a617f6b808f152cc3028a9 (patch)
tree30614bb8beaf76326367a5efffb3df8e733b709f /lib/private
parent14c592fe865748f38dd6ee31634d053f83a8e791 (diff)
downloadnextcloud-server-20738d287e456ddb05a617f6b808f152cc3028a9.tar.gz
nextcloud-server-20738d287e456ddb05a617f6b808f152cc3028a9.zip
Properly detect streamCopy errors
Now checking whether the written bytes match the number of read bytes.
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/helper.php16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 04c063145ba..f4992744ad9 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -594,13 +594,23 @@ class OC_Helper {
if (!$source or !$target) {
return array(0, false);
}
+ $bufSize = 8192;
$result = true;
$count = 0;
while (!feof($source)) {
- if (($c = fwrite($target, fread($source, 8192))) === false) {
+ $buf = fread($source, $bufSize);
+ $bytesWritten = fwrite($target, $buf);
+ if ($bytesWritten !== false) {
+ $count += $bytesWritten;
+ }
+ // note: strlen is expensive so only use it when necessary,
+ // on the last block
+ if ($bytesWritten === false
+ || ($bytesWritten < $bufSize && $bytesWritten < strlen($buf))
+ ) {
+ // write error, could be disk full ?
$result = false;
- } else {
- $count += $c;
+ break;
}
}
return array($count, $result);