From d8d4420f227588acedb50918a1b794a2c68a7ade Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Mon, 27 Feb 2012 12:20:37 +0100
Subject: [PATCH] some cleanup in filestorage

---
 lib/filestorage/local.php |  4 +---
 lib/filesystemview.php    | 16 ++++------------
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 7d889fbce5..8acfe504cb 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -96,9 +96,7 @@ class OC_Filestorage_Local extends OC_Filestorage{
 			$source=substr($path1,strrpos($path1,'/')+1);
 			$path2.=$source;
 		}
-		if($return=copy($this->datadir.$path1,$this->datadir.$path2)){
-		}
-		return $return;
+		return copy($this->datadir.$path1,$this->datadir.$path2);
 	}
 	public function fopen($path,$mode){
 		if($return=fopen($this->datadir.$path,$mode)){
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index 9f0a88f8ab..b014c3272f 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -173,13 +173,11 @@ class OC_FilesystemView {
 		if(is_resource($data)){//not having to deal with streams in file_put_contents makes life easier
 			$target=$this->fopen($path,'w');
 			if($target){
-				while(!feof($data)){
-					fwrite($target,fread($data,8192));
-				}
+				$count=OC_Helper::streamCopy($data,$target);
 				fclose($target);
 				fclose($data);
 				OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path));
-				return true;
+				return $count>0;
 			}else{
 				return false;
 			}
@@ -204,9 +202,7 @@ class OC_FilesystemView {
 				}else{
 					$source=$this->fopen($path1,'r');
 					$target=$this->fopen($path2,'w');
-					while (!feof($source)){
-						fwrite($target,fread($source,8192));
-					}
+					$count=OC_Helper::streamCopy($data,$target);
 					$storage1=$this->getStorage($path1);
 					$storage1->unlink($this->getInternalPath($path1));
 				}
@@ -236,11 +232,7 @@ class OC_FilesystemView {
 				}else{
 					$source=$this->fopen($path1,'r');
 					$target=$this->fopen($path2,'w');
-					if($target and $source){
-						while (!feof($source)){
-							fwrite($target,fread($source,8192));
-						}
-					}
+					$count=OC_Helper::streamCopy($data,$target);
 				}
         OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2));
 				if(!$exists){
-- 
GitLab