aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-02-22 16:43:11 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-02-22 16:43:11 +0100
commitd8137fdf66a513d0de4bb234d0427ff27ca40106 (patch)
treed02f9782f8e7e77670f03469847b3044e1172f53
parent5b949596867c986916568e5bea2003e04102aa71 (diff)
downloadnextcloud-server-d8137fdf66a513d0de4bb234d0427ff27ca40106.tar.gz
nextcloud-server-d8137fdf66a513d0de4bb234d0427ff27ca40106.zip
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
-rw-r--r--apps/files_sharing/lib/sharedstorage.php3
-rw-r--r--lib/files/storage/common.php4
-rw-r--r--lib/files/view.php8
-rw-r--r--lib/helper.php9
-rw-r--r--lib/public/files.php3
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;
}
/**