use filesystem abstraction layer to copy file versions
This commit is contained in:
parent
4bc9e4e012
commit
aec6eea235
3 changed files with 13 additions and 4 deletions
|
@ -68,6 +68,9 @@ class Storage {
|
|||
*/
|
||||
public static function store($filename) {
|
||||
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
||||
$files_view = \OCP\Files::getStorage("files");
|
||||
$users_view = \OCP\Files::getStorage("files_versions");
|
||||
$users_view->chroot(\OCP\User::getUser().'/');
|
||||
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
|
||||
$pos = strpos($source, '/files', 1);
|
||||
$uid = substr($source, 1, $pos - 1);
|
||||
|
@ -79,8 +82,13 @@ class Storage {
|
|||
$filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/files';
|
||||
Storage::init();
|
||||
|
||||
//check if source file already exist as version to avoid recursions.
|
||||
if ($users_view->file_exists($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if filename is a directory
|
||||
if(is_dir($filesfoldername.'/'.$filename)){
|
||||
if($files_view->is_dir($filename)){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -95,7 +103,7 @@ class Storage {
|
|||
}
|
||||
|
||||
// check filesize
|
||||
if(filesize($filesfoldername.'/'.$filename)>\OCP\Config::getSystemValue('files_versionsmaxfilesize', Storage::DEFAULTMAXFILESIZE)){
|
||||
if($files_view->filesize($filename)>\OCP\Config::getSystemValue('files_versionsmaxfilesize', Storage::DEFAULTMAXFILESIZE)){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -116,7 +124,7 @@ class Storage {
|
|||
if(!file_exists($versionsFolderName.'/'.$info['dirname'])) mkdir($versionsFolderName.'/'.$info['dirname'],0700,true);
|
||||
|
||||
// store a new version of a file
|
||||
copy($filesfoldername.'/'.$filename,$versionsFolderName.'/'.$filename.'.v'.time());
|
||||
$users_view->copy('files'.$filename, 'versions'.$filename.'.v'.time());
|
||||
|
||||
// expire old revisions if necessary
|
||||
Storage::expire($filename);
|
||||
|
|
|
@ -153,6 +153,7 @@ class OC_Filesystem{
|
|||
if($path[0]!=='/'){
|
||||
$path='/'.$path;
|
||||
}
|
||||
$path=str_replace('//', '/',$path);
|
||||
$foundMountPoint='';
|
||||
foreach(OC_Filesystem::$mounts as $mountpoint=>$storage){
|
||||
if($mountpoint==$path){
|
||||
|
|
|
@ -314,7 +314,7 @@ class OC_FilesystemView {
|
|||
}else{
|
||||
$source=$this->fopen($path1,'r');
|
||||
$target=$this->fopen($path2,'w');
|
||||
$count=OC_Helper::streamCopy($source,$target);
|
||||
$result=OC_Helper::streamCopy($source,$target);
|
||||
}
|
||||
OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2));
|
||||
if(!$exists){
|
||||
|
|
Loading…
Reference in a new issue