]> source.dussan.org Git - nextcloud-server.git/commitdiff
move implementation of from/toTmpFile from the file storage to the filesystem
authorRobin Appelman <icewind@owncloud.com>
Sat, 11 Feb 2012 14:48:31 +0000 (15:48 +0100)
committerRobin Appelman <icewind@owncloud.com>
Tue, 21 Feb 2012 19:48:48 +0000 (20:48 +0100)
lib/filestorage.php
lib/filestorage/local.php
lib/filesystemview.php

index 4523144f6f4230031ca805cfb3322f8a67285f3a..d420427225b42afad0767c323ccab9b8dc4298d2 100644 (file)
@@ -45,8 +45,6 @@ class OC_Filestorage{
        public function rename($path1,$path2){}
        public function copy($path1,$path2){}
        public function fopen($path,$mode){}
-       public function toTmpFile($path){}//copy the file to a temporary file, used for cross-storage file actions
-       public function fromTmpFile($tmpPath,$path){}//copy a file from a temporary file, used for cross-storage file actions
        public function getMimeType($path){}
        public function hash($type,$path,$raw){}
        public function free_space($path){}
index ee4b267bcd496192ac93bd2b7b1d058f156fb5da..de1f83e3e14079c3ffb100441be478adcf48debf 100644 (file)
@@ -171,28 +171,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
                }
        }
 
-       public function toTmpFile($path){
-               $tmpFolder=get_temp_dir();
-               $filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.')));
-               $fileStats = stat($this->datadir.$path);
-               if(copy($this->datadir.$path,$filename)){
-                       touch($filename, $fileStats['mtime'], $fileStats['atime']);
-                       return $filename;
-               }else{
-                       return false;
-               }
-       }
-
-       public function fromTmpFile($tmpFile,$path){
-               $fileStats = stat($tmpFile);
-               if(rename($tmpFile,$this->datadir.$path)){
-                       touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
-                       return true;
-               }else{
-                       return false;
-               }
-       }
-
        private function delTree($dir) {
                $dirRelative=$dir;
                $dir=$this->datadir.$dir;
index 0ce803be2b1a5bce6863a54112a689af288de306..592fd972a7845f49f3ca3d4a1fe924c9ecd29d08 100644 (file)
@@ -254,29 +254,25 @@ class OC_FilesystemView {
                return $this->basicOperation('fopen',$path,$hooks,$mode);
        }
        public function toTmpFile($path){
-               if(OC_FileProxy::runPreProxies('toTmpFile',$path) and OC_Filesystem::isValidPath($path) and $storage=$this->getStorage($path)){
-                       OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_read, array( OC_Filesystem::signal_param_path => $path));
-                       return $storage->toTmpFile($this->getInternalPath($path));
+               if(OC_Filesystem::isValidPath($path)){
+                       $source=$this->fopen($path,'r');
+                       $tmpFile=tempnam(get_temp_dir(),'OC_TMP_').substr($path,strrpos($path,'.'));
+                       if($source){
+                               return file_put_contents($tmpFile,$source);
+                       }
                }
        }
        public function fromTmpFile($tmpFile,$path){
-               if(OC_FileProxy::runPreProxies('copy',$tmpFile,$path) and OC_Filesystem::isValidPath($path) and $storage=$this->getStorage($path)){
-                       $run=true;
-                       $exists=$this->file_exists($path);
-                       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));
-                       }
-                       if($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){
-                               $result=$storage->fromTmpFile($tmpFile,$this->getInternalPath($path));
-                               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));
-                               return $result;
+               if(OC_Filesystem::isValidPath($path)){
+                       $source=fopen($tmpFile,'r');
+                       if($source){
+                               $this->file_put_contents($path,$source);
+                               unlink($tmpFile);
+                               return true;
+                       }else{
                        }
+               }else{
+                       error_log('invalid path');
                }
        }