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
This commit is contained in:
Frank Karlitschek 2013-02-25 02:04:12 -08:00
commit 9ee5069f2a
5 changed files with 18 additions and 12 deletions

View File

@ -315,7 +315,8 @@ class Shared extends \OC\Files\Storage\Common {
if ($this->isCreatable(dirname($path2))) { if ($this->isCreatable(dirname($path2))) {
$source = $this->fopen($path1, 'r'); $source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w'); $target = $this->fopen($path2, 'w');
return \OC_Helper::streamCopy($source, $target); list ($count, $result) = \OC_Helper::streamCopy($source, $target);
return $result;
} }
return false; return false;
} }

View File

@ -97,8 +97,8 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function copy($path1, $path2) { public function copy($path1, $path2) {
$source=$this->fopen($path1, 'r'); $source=$this->fopen($path1, 'r');
$target=$this->fopen($path2, 'w'); $target=$this->fopen($path2, 'w');
$count=\OC_Helper::streamCopy($source, $target); list($count, $result) = \OC_Helper::streamCopy($source, $target);
return $count>0; return $result;
} }
/** /**

View File

@ -285,7 +285,7 @@ class View {
} }
$target = $this->fopen($path, 'w'); $target = $this->fopen($path, 'w');
if ($target) { if ($target) {
$count = \OC_Helper::streamCopy($data, $target); list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target); fclose($target);
fclose($data); fclose($data);
if ($this->fakeRoot == Filesystem::getRoot()) { if ($this->fakeRoot == Filesystem::getRoot()) {
@ -303,7 +303,7 @@ class View {
); );
} }
\OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $count > 0; return $result;
} else { } else {
return false; return false;
} }
@ -361,10 +361,9 @@ class View {
} else { } else {
$source = $this->fopen($path1 . $postFix1, 'r'); $source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w'); $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); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
$storage1->unlink($internalPath1); $storage1->unlink($internalPath1);
$result = $count > 0;
} }
if ($this->fakeRoot == Filesystem::getRoot()) { if ($this->fakeRoot == Filesystem::getRoot()) {
\OC_Hook::emit( \OC_Hook::emit(
@ -444,7 +443,7 @@ class View {
} else { } else {
$source = $this->fopen($path1 . $postFix1, 'r'); $source = $this->fopen($path1 . $postFix1, 'r');
$target = $this->fopen($path2 . $postFix2, 'w'); $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()) { if ($this->fakeRoot == Filesystem::getRoot()) {
\OC_Hook::emit( \OC_Hook::emit(

View File

@ -513,11 +513,16 @@ class OC_Helper {
if(!$source or !$target) { if(!$source or !$target) {
return false; return false;
} }
$count=0; $result = true;
$count = 0;
while(!feof($source)) { 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);
} }
/** /**

View File

@ -62,7 +62,8 @@ class Files {
* @return int the number of bytes copied * @return int the number of bytes copied
*/ */
public static function streamCopy( $source, $target ) { public static function streamCopy( $source, $target ) {
return(\OC_Helper::streamCopy( $source, $target )); list($count, $result) = \OC_Helper::streamCopy( $source, $target );
return $count;
} }
/** /**