From 5b949596867c986916568e5bea2003e04102aa71 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 14:56:50 +0100 Subject: using the number of writen bytes as indicator if streamCopy() was successfully. Instead check if fwrite returns the number of bytes or false --- lib/files/view.php | 3 +-- lib/helper.php | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/files/view.php b/lib/files/view.php index 9ac08c98082..11edbadab9b 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -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); + $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( diff --git a/lib/helper.php b/lib/helper.php index add5c66e7be..2c9cd36b199 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -513,11 +513,13 @@ class OC_Helper { if(!$source or !$target) { return false; } - $count=0; + $result=true; while(!feof($source)) { - $count+=fwrite($target, fread($source, 8192)); + if (fwrite($target, fread($source, 8192)) === false) { + $result = false; + } } - return $count; + return $result; } /** -- cgit v1.2.3 From d8137fdf66a513d0de4bb234d0427ff27ca40106 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 16:43:11 +0100 Subject: return both, count and result if the operation succeeded or failed. Maybe in some cases it is useful to know how much bytes where copied --- apps/files_sharing/lib/sharedstorage.php | 3 ++- lib/files/storage/common.php | 4 ++-- lib/files/view.php | 8 ++++---- lib/helper.php | 9 ++++++--- lib/public/files.php | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 65812b7e2fd..e920329ae49 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -314,7 +314,8 @@ class Shared extends \OC\Files\Storage\Common { if ($this->isCreatable(dirname($path2))) { $source = $this->fopen($path1, 'r'); $target = $this->fopen($path2, 'w'); - return \OC_Helper::streamCopy($source, $target); + list ($count, $result) = \OC_Helper::streamCopy($source, $target); + return $result; } return false; } diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 4e7a73e5d4a..fd9ae844a8e 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 11edbadab9b..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,7 +361,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); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); $storage1->unlink($internalPath1); } @@ -443,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 2c9cd36b199..7420a79eb2d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -513,13 +513,16 @@ class OC_Helper { if(!$source or !$target) { return false; } - $result=true; + $result = true; + $count = 0; while(!feof($source)) { - if (fwrite($target, fread($source, 8192)) === false) { + if ($c = fwrite($target, fread($source, 8192)) === false) { $result = false; + } else { + $count += $c; } } - return $result; + 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; } /** -- cgit v1.2.3 From eabfd9b69b11fd0859dee919d702b39bd50369dd Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 16:45:57 +0100 Subject: put value assignment into brackets --- lib/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helper.php b/lib/helper.php index 7420a79eb2d..41985ca57a7 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -516,7 +516,7 @@ class OC_Helper { $result = true; $count = 0; while(!feof($source)) { - if ($c = fwrite($target, fread($source, 8192)) === false) { + if ( ( $c = fwrite($target, fread($source, 8192)) ) === false) { $result = false; } else { $count += $c; -- cgit v1.2.3