move implementation of from/toTmpFile from the file storage to the filesystem
This commit is contained in:
parent
6658f51098
commit
1cffeefa06
|
@ -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){}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue