diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-02-11 15:48:31 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-02-21 20:48:48 +0100 |
commit | 1cffeefa069075054f9c2f676b84ddc02b56232c (patch) | |
tree | 240462f92b81db768d9c227974020579666c4849 /lib | |
parent | 6658f510986aff0e41fee37319a1b0eefa98a4d0 (diff) | |
download | nextcloud-server-1cffeefa069075054f9c2f676b84ddc02b56232c.tar.gz nextcloud-server-1cffeefa069075054f9c2f676b84ddc02b56232c.zip |
move implementation of from/toTmpFile from the file storage to the filesystem
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filestorage.php | 2 | ||||
-rw-r--r-- | lib/filestorage/local.php | 22 | ||||
-rw-r--r-- | lib/filesystemview.php | 34 |
3 files changed, 15 insertions, 43 deletions
diff --git a/lib/filestorage.php b/lib/filestorage.php index 4523144f6f4..d420427225b 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 ee4b267bcd4..de1f83e3e14 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 0ce803be2b1..592fd972a78 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'); } } |