From 1cffeefa069075054f9c2f676b84ddc02b56232c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 11 Feb 2012 15:48:31 +0100 Subject: [PATCH] move implementation of from/toTmpFile from the file storage to the filesystem --- lib/filestorage.php | 2 -- lib/filestorage/local.php | 22 ---------------------- lib/filesystemview.php | 34 +++++++++++++++------------------- 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/lib/filestorage.php b/lib/filestorage.php index 4523144f6f..d420427225 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -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){} diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index ee4b267bcd..de1f83e3e1 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -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; diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 0ce803be2b..592fd972a7 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -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'); } }