From c121a1a1e7d9ae554005b8438d8ad999cdacc601 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 15 Feb 2012 16:23:00 +0100 Subject: [PATCH] implement file_put_contents with stream data using fopen --- apps/files_encryption/lib/proxy.php | 6 +----- lib/filesystemview.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index be6ffa4f44d..7974d68d487 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -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); } } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 592fd972a78..58d5b3af715 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -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')); -- 2.39.5