]> source.dussan.org Git - nextcloud-server.git/commitdiff
use filesystem abstraction layer to copy file versions
authorBjoern Schiessle <schiessle@owncloud.com>
Tue, 3 Jul 2012 16:01:05 +0000 (18:01 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Tue, 3 Jul 2012 16:25:49 +0000 (18:25 +0200)
apps/files_versions/versions.php
lib/filesystem.php
lib/filesystemview.php

index 7ed5f257505ea95ac300450cc112d5c9e11d7e78..1a1a2e9ecf8733de7be03b64faaa519d2946e1b4 100644 (file)
@@ -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");\r
+                       $users_view = \OCP\Files::getStorage("files_versions");\r
+                       $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.\r
+                       if ($users_view->file_exists($filename)) {\r
+                               return false;\r
+                       }
+                       
                        // 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);
index 0ab3bd69acd85836bf05dc30da853ba5a5782e50..65318fa3ab695214e52723d16aa289fa2610c19d 100644 (file)
@@ -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){
index d474b61b98ce1f0be352738275f1fc73e1ed7c90..448663bb0811b5906499d2c15a11ab910e343e69 100644 (file)
@@ -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){