summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFrank Karlitschek <frank@owncloud.org>2013-02-25 02:04:12 -0800
committerFrank Karlitschek <frank@owncloud.org>2013-02-25 02:04:12 -0800
commit9ee5069f2a1d76c899eeef6cec0f06387764fabd (patch)
treee1d381e72428a2d8f03b19ed46962c7914e1eaef /lib
parent8f659169047f2dcdd6f7a15b2b31b537fe858953 (diff)
parenteabfd9b69b11fd0859dee919d702b39bd50369dd (diff)
downloadnextcloud-server-9ee5069f2a1d76c899eeef6cec0f06387764fabd.tar.gz
nextcloud-server-9ee5069f2a1d76c899eeef6cec0f06387764fabd.zip
Merge pull request #1856 from owncloud/fix_error_handling_stream_copy
don't use the number of written bytes as indicator if streamCopy() was successful
Diffstat (limited to 'lib')
-rw-r--r--lib/files/storage/common.php4
-rw-r--r--lib/files/view.php9
-rw-r--r--lib/helper.php11
-rw-r--r--lib/public/files.php3
4 files changed, 16 insertions, 11 deletions
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index 8faacdf01d8..f9c6bdfce0c 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -97,8 +97,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function copy($path1, $path2) {
$source=$this->fopen($path1, 'r');
$target=$this->fopen($path2, 'w');
- $count=\OC_Helper::streamCopy($source, $target);
- return $count>0;
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ return $result;
}
/**
diff --git a/lib/files/view.php b/lib/files/view.php
index 9ac08c98082..f48d0c8b225 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -285,7 +285,7 @@ class View {
}
$target = $this->fopen($path, 'w');
if ($target) {
- $count = \OC_Helper::streamCopy($data, $target);
+ list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
if ($this->fakeRoot == Filesystem::getRoot()) {
@@ -303,7 +303,7 @@ class View {
);
}
\OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
- return $count > 0;
+ return $result;
} else {
return false;
}
@@ -361,10 +361,9 @@ class View {
} else {
$source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w');
- $count = \OC_Helper::streamCopy($source, $target);
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
$storage1->unlink($internalPath1);
- $result = $count > 0;
}
if ($this->fakeRoot == Filesystem::getRoot()) {
\OC_Hook::emit(
@@ -444,7 +443,7 @@ class View {
} else {
$source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w');
- $result = \OC_Helper::streamCopy($source, $target);
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
}
if ($this->fakeRoot == Filesystem::getRoot()) {
\OC_Hook::emit(
diff --git a/lib/helper.php b/lib/helper.php
index add5c66e7be..41985ca57a7 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -513,11 +513,16 @@ class OC_Helper {
if(!$source or !$target) {
return false;
}
- $count=0;
+ $result = true;
+ $count = 0;
while(!feof($source)) {
- $count+=fwrite($target, fread($source, 8192));
+ if ( ( $c = fwrite($target, fread($source, 8192)) ) === false) {
+ $result = false;
+ } else {
+ $count += $c;
+ }
}
- return $count;
+ return array($count, $result);
}
/**
diff --git a/lib/public/files.php b/lib/public/files.php
index c2945b200e8..700bf574537 100644
--- a/lib/public/files.php
+++ b/lib/public/files.php
@@ -62,7 +62,8 @@ class Files {
* @return int the number of bytes copied
*/
public static function streamCopy( $source, $target ) {
- return(\OC_Helper::streamCopy( $source, $target ));
+ list($count, $result) = \OC_Helper::streamCopy( $source, $target );
+ return $count;
}
/**