]> source.dussan.org Git - nextcloud-server.git/commitdiff
Run pre and post proxies for file_put_contents() streams
authorMichael Gapczynski <mtgap@owncloud.com>
Fri, 27 Jul 2012 02:53:55 +0000 (22:53 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Mon, 30 Jul 2012 14:07:19 +0000 (10:07 -0400)
Conflicts:
lib/filesystemview.php

lib/filesystemview.php

index f147cf5b244f55185968417053a74880370e1de9..a363cee0b8a1cbfb904d4eecdd0c2609bd3251c8 100644 (file)
@@ -198,29 +198,56 @@ class OC_FilesystemView {
        public function file_get_contents($path){
                return $this->basicOperation('file_get_contents',$path,array('read'));
        }
-       public function file_put_contents($path,$data){
-               if(is_resource($data)){//not having to deal with streams in file_put_contents makes life easier
-                       $exists=$this->file_exists($path);
-                       $run=true;
-                       if(!$exists){
-                               OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
-                       }
-                       OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
-                       if(!$run){
-                               return false;
-                       }
-                       $target=$this->fopen($path,'w');
-                       if($target){
-                               $count=OC_Helper::streamCopy($data,$target);
-                               fclose($target);
-                               fclose($data);
-                               if(!$exists){
-                                       OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array( OC_Filesystem::signal_param_path => $path));
+       public function file_put_contents($path, $data) {
+               if(is_resource($data)) {//not having to deal with streams in file_put_contents makes life easier
+                       $absolutePath = $this->getAbsolutePath($path);
+                       if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath) && OC_Filesystem::isValidPath($path)) {
+                               $path = $this->getRelativePath($absolutePath);
+                               $exists = $this->file_exists($path);
+                               $run = true;
+                               if(!$exists) {
+                                       OC_Hook::emit(
+                                               OC_Filesystem::CLASSNAME,
+                                               OC_Filesystem::signal_create,
+                                               array(
+                                                       OC_Filesystem::signal_param_path => $path,
+                                                       OC_Filesystem::signal_param_run => &$run
+                                               )
+                                       );
+                               }
+                               OC_Hook::emit(
+                                       OC_Filesystem::CLASSNAME,
+                                       OC_Filesystem::signal_write,
+                                       array(
+                                               OC_Filesystem::signal_param_path => $path,
+                                               OC_Filesystem::signal_param_run => &$run
+                                       )
+                               );
+                               if(!$run) {
+                                       return false;
+                               }
+                               $target=$this->fopen($path, 'w');
+                               if($target) {
+                                       $count=OC_Helper::streamCopy($data, $target);
+                                       fclose($target);
+                                       fclose($data);
+                                       if(!$exists) {
+                                               OC_Hook::emit(
+                                                       OC_Filesystem::CLASSNAME,
+                                                       OC_Filesystem::signal_post_create,
+                                                       array( OC_Filesystem::signal_param_path => $path)
+                                               );
+                                       }
+                                       OC_Hook::emit(
+                                               OC_Filesystem::CLASSNAME,
+                                               OC_Filesystem::signal_post_write,
+                                               array( OC_Filesystem::signal_param_path => $path)
+                                       );
+                                       OC_FileProxy::runPostProxies('hash', $absolutePath, $count);
+                                       return $count > 0;
+                               }else{
+                                       return false;
                                }
-                               OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path));
-                               return $count>0;
-                       }else{
-                               return false;
                        }
                }else{
                        return $this->basicOperation('file_put_contents',$path,array('create','write'),$data);