]> source.dussan.org Git - nextcloud-server.git/commitdiff
move2trash() handles keyfiles
authorBjörn Schießle <schiessle@owncloud.com>
Tue, 19 Feb 2013 17:45:46 +0000 (18:45 +0100)
committerBjörn Schießle <schiessle@owncloud.com>
Tue, 19 Feb 2013 17:45:46 +0000 (18:45 +0100)
apps/files_trashbin/lib/trash.php

index 8d54a471b422ab719fa317a59cef6365d6e9bd68..1c0306ea90a1a7c63baa915db128602595c61280 100644 (file)
@@ -37,7 +37,9 @@ class Trashbin {
                $view = new \OC_FilesystemView('/'. $user);\r
                if (!$view->is_dir('files_trashbin')) {\r
                        $view->mkdir('files_trashbin');\r
-                       $view->mkdir("versions_trashbin");\r
+                       $view->mkdir("files_trashbin/files");
+                       $view->mkdir("files_trashbin/versions");
+                       $view->mkdir("files_trashbin/keyfiles");\r
                }\r
 \r
                $path_parts = pathinfo($file_path);\r
@@ -54,31 +56,38 @@ class Trashbin {
                }
                \r
                if (  ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
-                       $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
-                       $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
+                       $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));\r
                }
-               $trashbinSize += self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view);
+               $trashbinSize += self::copy_recursive($file_path, 'files_trashbin/files/'.$deleted.'.d'.$timestamp, $view);
 
-               if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) {\r
+               if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) {\r
                        $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)");\r
                        $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user));
                        if ( !$result ) { // if file couldn't be added to the database than also don't store it in the trash bin.
-                               $view->deleteAll('files_trashbin/'.$deleted.'.d'.$timestamp);
+                               $view->deleteAll('files_trashbin/files/'.$deleted.'.d'.$timestamp);
                                \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
                                return;
                        }\r
-       \r
+                       
+                       // Take core of file versions\r
                        if ( \OCP\App::isEnabled('files_versions') ) {\r
                                if ( $view->is_dir('files_versions'.$file_path) ) {
                                        $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path));\r
-                                       $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);\r
+                                       $view->rename('files_versions'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp);\r
                                } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) {\r
                                        foreach ($versions as $v) {
                                                $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);\r
-                                               $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);\r
+                                               $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions'. $deleted.'.v'.$v['version'].'.d'.$timestamp);\r
                                        }\r
                                }\r
                        }
+                       
+                       // Take care of encryption keys\r
+                       if ( \OCP\App::isEnabled('files_encryption') ) {\r
+                               $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_encryption/keyfiles/'.$file_path));\r
+                               $view->rename('files_encryption'.$file_path, 'files_trashbin/keyfiles'. $deleted.'.d'.$timestamp);\r
+                       }
+                       
                } else {
                        \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR);
                }