]> source.dussan.org Git - nextcloud-server.git/commitdiff
implement file_put_contents with stream data using fopen
authorRobin Appelman <icewind@owncloud.com>
Wed, 15 Feb 2012 15:23:00 +0000 (16:23 +0100)
committerRobin Appelman <icewind@owncloud.com>
Tue, 21 Feb 2012 19:48:48 +0000 (20:48 +0100)
apps/files_encryption/lib/proxy.php
lib/filesystemview.php

index be6ffa4f44d4f48b85f5ac264e87806720bd1a43..7974d68d48753977bbdb8930734116b2cd096977 100644 (file)
@@ -70,11 +70,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
        
        public function preFile_put_contents($path,&$data){
                if(self::shouldEncrypt($path)){
-                       if (is_resource($data)) {
-                               $id=md5($path);
-                               OC_CryptStream::$sourceStreams[$id]=array('path'=>$path,'stream'=>$data);
-                               $data=fopen('crypt://streams/'.$id,'r');
-                       }else{
+                       if (!is_resource($data)) {//stream put contents should have been converter to fopen
                                $data=OC_Crypt::blockEncrypt($data);
                        }
                }
index 592fd972a7845f49f3ca3d4a1fe924c9ecd29d08..58d5b3af715d46d2de27bbb12122fe1437fe63bf 100644 (file)
@@ -163,7 +163,21 @@ class OC_FilesystemView {
                return $this->basicOperation('file_get_contents',$path,array('read'));
        }
        public function file_put_contents($path,$data){
-               return $this->basicOperation('file_put_contents',$path,array('create','write'),$data);
+               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));
+                               }
+                               fclose($target);
+                               fclose($data);
+                               return true;
+                       }else{
+                               return false;
+                       }
+               }else{
+                       return $this->basicOperation('file_put_contents',$path,array('create','write'),$data);
+               }
        }
        public function unlink($path){
                return $this->basicOperation('unlink',$path,array('delete'));