summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-04-19 10:31:42 +0200
committerFlorin Peter <github@florin-peter.de>2013-04-28 20:45:51 +0200
commitcb65b7ca9d485f1a2ebf71ba2d60cb034669f945 (patch)
tree9fd59fd36d54d495af75124436377f13efffa6c8 /apps/files_trashbin
parent1f194b7bdcbac868525b164b29814d3373b6e818 (diff)
downloadnextcloud-server-cb65b7ca9d485f1a2ebf71ba2d60cb034669f945.tar.gz
nextcloud-server-cb65b7ca9d485f1a2ebf71ba2d60cb034669f945.zip
move encryption keys to trash bin
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/trash.php107
1 files changed, 76 insertions, 31 deletions
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index f0b56eef014..82c4601a026 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -46,7 +46,7 @@ class Trashbin {
$path_parts = pathinfo($file_path);
- $deleted = $path_parts['basename'];
+ $filename = $path_parts['basename'];
$location = $path_parts['dirname'];
$timestamp = time();
$mime = $view->getMimeType('files'.$file_path);
@@ -62,45 +62,24 @@ class Trashbin {
$trashbinSize = self::calculateSize(new \OC\Files\View('/'. $user.'/files_trashbin'));
}
- $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$deleted.'.d'.$timestamp, $view);
+ $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$filename.'.d'.$timestamp, $view);
- if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) {
+ if ( $view->file_exists('files_trashbin/files/'.$filename.'.d'.$timestamp) ) {
$trashbinSize += $sizeOfAddedFiles;
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
- $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user));
+ $result = $query->execute(array($filename, $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/files/'.$deleted.'.d'.$timestamp);
+ $view->deleteAll('files_trashbin/files/'.$filename.'.d'.$timestamp);
\OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
return;
}
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash',
array('filePath' => \OC\Files\Filesystem::normalizePath($file_path),
- 'trashPath' => \OC\Files\Filesystem::normalizePath($deleted.'.d'.$timestamp)));
-
- // Take care of file versions
- if ( \OCP\App::isEnabled('files_versions') ) {
- if ( $view->is_dir('files_versions/'.$file_path) ) {
- $trashbinSize += self::calculateSize(new \OC\Files\View('/'. $user.'/files_versions/'.$file_path));
- $view->rename('files_versions/'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp);
- } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path) ) {
- foreach ($versions as $v) {
- $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);
- $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
- }
- }
- }
-
- // Take care of encryption keys
- $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path);
- if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile.'.key') ) {
- if ( $view->is_dir('files'.$file_path) ) {
- $trashbinSize += self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile));
- $view->rename($keyfile, 'files_trashbin/keyfiles/'. $deleted.'.d'.$timestamp);
- } else {
- $trashbinSize += $view->filesize($keyfile.'.key');
- $view->rename($keyfile.'.key', 'files_trashbin/keyfiles/'. $deleted.'.key.d'.$timestamp);
- }
- }
+ 'trashPath' => \OC\Files\Filesystem::normalizePath($filename.'.d'.$timestamp)));
+
+ $trashbinSize += self::retainVersions($view, $file_path, $filename, $timestamp);
+ $trashbinSize += self::retainEncryptionKeys($view, $file_path, $filename, $timestamp);
+
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR);
}
@@ -111,6 +90,72 @@ class Trashbin {
}
+ /**
+ * Move file versions to trash so that they can be restored later
+ *
+ * @param $file_path path to original file
+ * @param $filename of deleted file
+ * @param $timestamp when the file was deleted
+ *
+ * @return size of stored versions
+ */
+ private static function retainVersions($view, $file_path, $filename, $timestamp) {
+ $size = 0;
+ if (\OCP\App::isEnabled('files_versions')) {
+ $user = \OCP\User::getUser();
+ if ($view->is_dir('files_versions/' . $file_path)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_versions/' . $file_path));
+ $view->rename('files_versions/' . $file_path, 'files_trashbin/versions' . $filename . '.d' . $timestamp);
+ } else if ($versions = \OCA\Files_Versions\Storage::getVersions($user, $file_path)) {
+ foreach ($versions as $v) {
+ $size += $view->filesize('files_versions' . $v['path'] . '.v' . $v['version']);
+ $view->rename('files_versions' . $v['path'] . '.v' . $v['version'], 'files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp);
+ }
+ }
+ }
+
+ return $size;
+ }
+
+ /**
+ * Move encryption keys to trash so that they can be restored later
+ *
+ * @param $file_path path to original file
+ * @param $filename of deleted file
+ * @param $timestamp when the file was deleted
+ *
+ * @return size of encryption keys
+ */
+ private static function retainEncryptionKeys($view, $file_path, $filename, $timestamp) {
+ $size = 0;
+
+ if (\OCP\App::isEnabled('files_encryption')) {
+
+ $user = \OCP\User::getUser();
+
+ //retain key files
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path);
+ if ($view->file_exists($keyfile . '.key')) {
+
+ $user = \OCP\User::getUser();
+ if ($view->is_dir('files' . $file_path)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
+ $view->rename($keyfile, 'files_trashbin/keyfiles/' . $filename . '.d' . $timestamp);
+ } else {
+ $size += $view->filesize($keyfile . '.key');
+ $view->rename($keyfile . '.key', 'files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp);
+ }
+ }
+
+ // retain per user encryption key for keyfile
+ $sharekeys = \OC\Files\Filesystem::normalizePath('files_encryption/share-keys/' . $file_path);
+ if ($view->is_dir($sharekeys)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys));
+ $view->rename($keyfile, 'files_trashbin/share-keys/' . $sharekeys . '.d' . $timestamp);
+ }
+ }
+ return $size;
+ }
/**
* restore files from trash bin