summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-04-30 20:53:56 +0200
committerFlorin Peter <github@florin-peter.de>2013-04-30 20:53:56 +0200
commitb2da07fe95b383c35ae0f0fd55756e0f409d4fcf (patch)
tree21b38224ec671ecf68bd9604a9a553a40f3f1677 /apps/files_trashbin
parentfbbc76f281f50afa3072d99e4e0d413df835b3d3 (diff)
parent4ab3614248df4834aa6e1a684760e89c641d4818 (diff)
downloadnextcloud-server-b2da07fe95b383c35ae0f0fd55756e0f409d4fcf.tar.gz
nextcloud-server-b2da07fe95b383c35ae0f0fd55756e0f409d4fcf.zip
Merge branch 'master' into files_encryption to get the latest files_trashbin app
Conflicts: apps/files/l10n/bn_BD.php apps/files/l10n/da.php apps/files/l10n/de.php apps/files/l10n/de_DE.php apps/files/l10n/fa.php apps/files/l10n/fi_FI.php apps/files/l10n/hr.php apps/files/l10n/ms_MY.php apps/files/l10n/ro.php apps/files/l10n/si_LK.php apps/files/l10n/sl.php apps/files/l10n/ta_LK.php apps/files_external/l10n/de_DE.php apps/files_external/l10n/et_EE.php apps/user_ldap/l10n/tr.php core/l10n/bg_BG.php l10n/af_ZA/files.po l10n/af_ZA/files_external.po l10n/ar/core.po l10n/ar/files.po l10n/ar/files_external.po l10n/be/files.po l10n/be/files_external.po l10n/bg_BG/core.po l10n/bg_BG/files.po l10n/bg_BG/files_external.po l10n/bg_BG/files_trashbin.po l10n/bg_BG/files_versions.po l10n/bg_BG/settings.po l10n/bn_BD/core.po l10n/bn_BD/files.po l10n/bn_BD/files_external.po l10n/ca/core.po l10n/ca/files.po l10n/ca/files_external.po l10n/cs_CZ/core.po l10n/cs_CZ/files.po l10n/cs_CZ/files_external.po l10n/cs_CZ/lib.po l10n/cy_GB/core.po l10n/cy_GB/files.po l10n/cy_GB/files_external.po l10n/cy_GB/settings.po l10n/da/core.po l10n/da/files.po l10n/da/files_external.po l10n/de/core.po l10n/de/files.po l10n/de/files_external.po l10n/de_DE/core.po l10n/de_DE/files.po l10n/de_DE/files_external.po l10n/el/core.po l10n/el/files.po l10n/el/files_external.po l10n/eo/core.po l10n/eo/files.po l10n/eo/files_external.po l10n/es/core.po l10n/es/files.po l10n/es/files_external.po l10n/es_AR/core.po l10n/es_AR/files.po l10n/es_AR/files_external.po l10n/et_EE/core.po l10n/et_EE/files.po l10n/et_EE/files_external.po l10n/eu/core.po l10n/eu/files.po l10n/eu/files_external.po l10n/fa/core.po l10n/fa/files.po l10n/fa/files_external.po l10n/fi/files.po l10n/fi_FI/core.po l10n/fi_FI/files.po l10n/fi_FI/files_external.po l10n/fr/core.po l10n/fr/files.po l10n/fr/files_external.po l10n/gl/core.po l10n/gl/files.po l10n/gl/files_external.po l10n/he/core.po l10n/he/files.po l10n/he/files_external.po l10n/hi/files.po l10n/hi/files_external.po l10n/hr/core.po l10n/hr/files.po l10n/hr/files_external.po l10n/hu_HU/core.po l10n/hu_HU/files.po l10n/hu_HU/files_external.po l10n/hy/files.po l10n/hy/files_external.po l10n/ia/core.po l10n/ia/files.po l10n/ia/files_external.po l10n/id/core.po l10n/id/files.po l10n/id/files_external.po l10n/is/core.po l10n/is/files.po l10n/is/files_external.po l10n/it/core.po l10n/it/files.po l10n/it/files_external.po l10n/ja_JP/core.po l10n/ja_JP/files.po l10n/ja_JP/files_external.po l10n/ka/files.po l10n/ka/files_external.po l10n/ka_GE/core.po l10n/ka_GE/files.po l10n/ka_GE/files_external.po l10n/kn/files.po l10n/kn/files_external.po l10n/ko/core.po l10n/ko/files.po l10n/ko/files_external.po l10n/ku_IQ/files.po l10n/ku_IQ/files_external.po l10n/lb/core.po l10n/lb/files.po l10n/lb/files_external.po l10n/lt_LT/core.po l10n/lt_LT/files.po l10n/lt_LT/files_external.po l10n/lv/core.po l10n/lv/files.po l10n/lv/files_external.po l10n/mk/core.po l10n/mk/files.po l10n/mk/files_external.po l10n/ms_MY/core.po l10n/ms_MY/files.po l10n/ms_MY/files_external.po l10n/my_MM/files.po l10n/my_MM/files_external.po l10n/nb_NO/core.po l10n/nb_NO/files.po l10n/nb_NO/files_external.po l10n/ne/files.po l10n/ne/files_external.po l10n/nl/core.po l10n/nl/files.po l10n/nl/files_external.po l10n/nn_NO/files.po l10n/nn_NO/files_external.po l10n/oc/core.po l10n/oc/files.po l10n/oc/files_external.po l10n/pl/core.po l10n/pl/files.po l10n/pl/files_external.po l10n/pl_PL/files.po l10n/pt_BR/core.po l10n/pt_BR/files.po l10n/pt_BR/files_external.po l10n/pt_PT/core.po l10n/pt_PT/files.po l10n/pt_PT/files_external.po l10n/ro/core.po l10n/ro/files.po l10n/ro/files_external.po l10n/ru/core.po l10n/ru/files.po l10n/ru/files_external.po l10n/ru_RU/core.po l10n/ru_RU/files.po l10n/si_LK/core.po l10n/si_LK/files.po l10n/si_LK/files_external.po l10n/sk/files.po l10n/sk/files_external.po l10n/sk_SK/core.po l10n/sk_SK/files.po l10n/sk_SK/files_external.po l10n/sl/core.po l10n/sl/files.po l10n/sl/files_external.po l10n/sq/core.po l10n/sq/files.po l10n/sq/files_external.po l10n/sr/core.po l10n/sr/files.po l10n/sr/files_external.po l10n/sr@latin/files.po l10n/sr@latin/files_external.po l10n/sv/core.po l10n/sv/files.po l10n/sv/files_external.po l10n/sw_KE/files.po l10n/sw_KE/files_external.po l10n/ta_LK/core.po l10n/ta_LK/files.po l10n/ta_LK/files_external.po l10n/te/files.po l10n/te/files_external.po l10n/templates/core.pot l10n/templates/files.pot l10n/templates/files_encryption.pot l10n/templates/files_external.pot l10n/templates/files_sharing.pot l10n/templates/files_trashbin.pot l10n/templates/files_versions.pot l10n/templates/lib.pot l10n/templates/settings.pot l10n/templates/user_ldap.pot l10n/templates/user_webdavauth.pot l10n/th_TH/core.po l10n/th_TH/files.po l10n/th_TH/files_external.po l10n/tr/core.po l10n/tr/files.po l10n/tr/files_external.po l10n/tr/user_ldap.po l10n/uk/core.po l10n/uk/files.po l10n/uk/files_external.po l10n/ur_PK/files.po l10n/ur_PK/files_external.po l10n/vi/core.po l10n/vi/files.po l10n/vi/files_external.po l10n/zh_CN.GB2312/core.po l10n/zh_CN.GB2312/files.po l10n/zh_CN.GB2312/files_external.po l10n/zh_CN/core.po l10n/zh_CN/files.po l10n/zh_CN/files_external.po l10n/zh_HK/core.po l10n/zh_HK/files.po l10n/zh_HK/files_external.po l10n/zh_TW/core.po l10n/zh_TW/files.po l10n/zh_TW/files_external.po lib/base.php lib/files/mount/mount.php
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/l10n/id.php8
-rw-r--r--apps/files_trashbin/l10n/nn_NO.php5
-rw-r--r--apps/files_trashbin/l10n/pl.php4
-rw-r--r--apps/files_trashbin/l10n/pt_PT.php2
-rw-r--r--apps/files_trashbin/l10n/ro.php1
-rw-r--r--apps/files_trashbin/l10n/sk_SK.php2
-rw-r--r--apps/files_trashbin/lib/trash.php395
7 files changed, 323 insertions, 94 deletions
diff --git a/apps/files_trashbin/l10n/id.php b/apps/files_trashbin/l10n/id.php
index e06c66784f2..62a63d515a3 100644
--- a/apps/files_trashbin/l10n/id.php
+++ b/apps/files_trashbin/l10n/id.php
@@ -2,13 +2,13 @@
"Couldn't delete %s permanently" => "Tidak dapat menghapus permanen %s",
"Couldn't restore %s" => "Tidak dapat memulihkan %s",
"perform restore operation" => "jalankan operasi pemulihan",
-"Error" => "kesalahan",
+"Error" => "Galat",
"delete file permanently" => "hapus berkas secara permanen",
-"Delete permanently" => "hapus secara permanen",
+"Delete permanently" => "Hapus secara permanen",
"Name" => "Nama",
"Deleted" => "Dihapus",
-"1 folder" => "1 map",
-"{count} folders" => "{count} map",
+"1 folder" => "1 folder",
+"{count} folders" => "{count} folder",
"1 file" => "1 berkas",
"{count} files" => "{count} berkas",
"Nothing in here. Your trash bin is empty!" => "Tempat sampah anda kosong!",
diff --git a/apps/files_trashbin/l10n/nn_NO.php b/apps/files_trashbin/l10n/nn_NO.php
index 14345ddcc4d..8166a024e58 100644
--- a/apps/files_trashbin/l10n/nn_NO.php
+++ b/apps/files_trashbin/l10n/nn_NO.php
@@ -1,5 +1,10 @@
<?php $TRANSLATIONS = array(
"Error" => "Feil",
+"Delete permanently" => "Slett for godt",
"Name" => "Namn",
+"1 folder" => "1 mappe",
+"{count} folders" => "{count} mapper",
+"1 file" => "1 fil",
+"{count} files" => "{count} filer",
"Delete" => "Slett"
);
diff --git a/apps/files_trashbin/l10n/pl.php b/apps/files_trashbin/l10n/pl.php
index 7fd1ab21ecd..5c9f558f11f 100644
--- a/apps/files_trashbin/l10n/pl.php
+++ b/apps/files_trashbin/l10n/pl.php
@@ -8,9 +8,9 @@
"Name" => "Nazwa",
"Deleted" => "Usunięte",
"1 folder" => "1 folder",
-"{count} folders" => "{count} foldery",
+"{count} folders" => "Ilość folderów: {count}",
"1 file" => "1 plik",
-"{count} files" => "{count} pliki",
+"{count} files" => "Ilość plików: {count}",
"Nothing in here. Your trash bin is empty!" => "Nic tu nie ma. Twój kosz jest pusty!",
"Restore" => "Przywróć",
"Delete" => "Usuń",
diff --git a/apps/files_trashbin/l10n/pt_PT.php b/apps/files_trashbin/l10n/pt_PT.php
index 7dfe610466b..ba85158b70e 100644
--- a/apps/files_trashbin/l10n/pt_PT.php
+++ b/apps/files_trashbin/l10n/pt_PT.php
@@ -13,6 +13,6 @@
"{count} files" => "{count} ficheiros",
"Nothing in here. Your trash bin is empty!" => "Não hà ficheiros. O lixo está vazio!",
"Restore" => "Restaurar",
-"Delete" => "Apagar",
+"Delete" => "Eliminar",
"Deleted Files" => "Ficheiros Apagados"
);
diff --git a/apps/files_trashbin/l10n/ro.php b/apps/files_trashbin/l10n/ro.php
index c03ef600f35..3af21b7e3f3 100644
--- a/apps/files_trashbin/l10n/ro.php
+++ b/apps/files_trashbin/l10n/ro.php
@@ -1,5 +1,6 @@
<?php $TRANSLATIONS = array(
"Error" => "Eroare",
+"Delete permanently" => "Stergere permanenta",
"Name" => "Nume",
"1 folder" => "1 folder",
"{count} folders" => "{count} foldare",
diff --git a/apps/files_trashbin/l10n/sk_SK.php b/apps/files_trashbin/l10n/sk_SK.php
index 7203f4c75fc..7cef36ef1c0 100644
--- a/apps/files_trashbin/l10n/sk_SK.php
+++ b/apps/files_trashbin/l10n/sk_SK.php
@@ -5,7 +5,7 @@
"Error" => "Chyba",
"delete file permanently" => "trvalo zmazať súbor",
"Delete permanently" => "Zmazať trvalo",
-"Name" => "Meno",
+"Name" => "Názov",
"Deleted" => "Zmazané",
"1 folder" => "1 priečinok",
"{count} folders" => "{count} priečinkov",
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index f0b56eef014..88c71a75ab0 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -39,14 +39,15 @@ class Trashbin {
$view = new \OC\Files\View('/'. $user);
if (!$view->is_dir('files_trashbin')) {
$view->mkdir('files_trashbin');
- $view->mkdir("files_trashbin/files");
- $view->mkdir("files_trashbin/versions");
- $view->mkdir("files_trashbin/keyfiles");
+ $view->mkdir('files_trashbin/files');
+ $view->mkdir('files_trashbin/versions');
+ $view->mkdir('files_trashbin/keyfiles');
+ $view->mkdir('files_trashbin/share-keys');
}
$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 +63,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);
-
- if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) {
+ $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$filename.'.d'.$timestamp, $view);
+
+ 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,15 +91,134 @@ class Trashbin {
}
+ /**
+ * Move file versions to trash so that they can be restored later
+ *
+ * @param \OC\Files\View $view
+ * @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')) {
+
+ // disable proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ $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);
+ }
+ }
+
+ // enable proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+ }
+
+ return $size;
+ }
+
+ /**
+ * Move encryption keys to trash so that they can be restored later
+ *
+ * @param \OC\Files\View $view
+ * @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();
+
+ // disable proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ // retain key files
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_encryption/keyfiles/' . $file_path);
+
+ if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) {
+ $user = \OCP\User::getUser();
+ // move keyfiles
+ if ($view->is_dir($keyfile)) {
+ $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 share keys
+ $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($sharekeys, 'files_trashbin/share-keys/' . $filename . '.d' . $timestamp);
+ } else {
+ // get local path to share-keys
+ $localShareKeysPath = $view->getLocalFile($sharekeys);
+
+ // handle share-keys
+ $matches = glob(preg_quote($localShareKeysPath).'*.shareKey');
+ foreach ($matches as $src) {
+ // get source file parts
+ $pathinfo = pathinfo($src);
+
+ // we only want to keep the owners key so we can access the private key
+ $ownerShareKey = $filename . '.' . $user. '.shareKey';
+
+ // if we found the share-key for the owner, we need to move it to files_trashbin
+ if($pathinfo['basename'] == $ownerShareKey) {
+
+ // calculate size
+ $size += $view->filesize($sharekeys. '.' . $user. '.shareKey');
+
+ // move file
+ $view->rename($sharekeys. '.' . $user. '.shareKey', 'files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp);
+ } else {
+
+ // calculate size
+ $size += filesize($src);
+
+ // don't keep other share-keys
+ unlink($src);
+ }
+ }
+
+ }
+
+ // enable proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+ }
+ return $size;
+ }
/**
* restore files from trash bin
* @param $file path to the deleted file
* @param $filename name of the file
* @param $timestamp time when the file was deleted
- */
+ *
+ * @return bool
+ */
public static function restore($file, $filename, $timestamp) {
- $user = \OCP\User::getUser();
+
+ $user = \OCP\User::getUser();
$view = new \OC\Files\View('/'.$user);
$trashbinSize = self::getTrashbinSize($user);
@@ -157,8 +256,17 @@ class Trashbin {
// we need a extension in case a file/dir with the same name already exists
$ext = self::getUniqueExtension($location, $filename, $view);
$mtime = $view->filemtime($source);
- if( $view->rename($source, $target.$ext) ) {
- $view->touch($target.$ext, $mtime);
+
+ // disable proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ // restore file
+ $restoreResult = $view->rename($source, $target.$ext);
+
+ // handle the restore result
+ if( $restoreResult ) {
+ $view->touch($target.$ext, $mtime);
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore',
array('filePath' => \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext),
'trashPath' => \OC\Files\Filesystem::normalizePath($file)));
@@ -167,68 +275,183 @@ class Trashbin {
} else {
$trashbinSize -= $view->filesize($target.$ext);
}
- // if versioning app is enabled, copy versions from the trash bin back to the original location
- if ( \OCP\App::isEnabled('files_versions') ) {
- if ($timestamp ) {
- $versionedFile = $filename;
- } else {
- $versionedFile = $file;
- }
- if ( $result[0]['type'] === 'dir' ) {
- $trashbinSize -= self::calculateSize(new \OC\Files\View('/'.$user.'/'.'files_trashbin/versions/'. $file));
- $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC\Files\Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext));
- } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {
- foreach ($versions as $v) {
- if ($timestamp ) {
- $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp);
- $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
- } else {
- $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v);
- $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
- }
- }
- }
- }
-
- // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!)
- $parts = pathinfo($file);
- if ( $result[0]['type'] === 'dir' ) {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$parts['dirname'].'/'.$filename);
- } else {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$parts['dirname'].'/'.$filename.'.key');
- }
- if ($timestamp) {
- $keyfile .= '.d'.$timestamp;
- }
- if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) {
- if ( $result[0]['type'] === 'dir' ) {
- $trashbinSize -= self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile));
- $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename);
- } else {
- $trashbinSize -= $view->filesize($keyfile);
- $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename.'.key');
- }
- }
-
+
+ $trashbinSize -= self::restoreVersions($view, $file, $filename, $ext, $location, $timestamp);
+ $trashbinSize -= self::restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp);
+
if ( $timestamp ) {
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?');
$query->execute(array($user,$filename,$timestamp));
}
self::setTrashbinSize($user, $trashbinSize);
-
+
+ // enable proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+
return true;
- } else {
- \OC_Log::write('files_trashbin', 'Couldn\'t restore file from trash bin, '.$filename, \OC_log::ERROR);
}
+ // enable proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+
return false;
}
+ /**
+ * @brief restore versions from trash bin
+ *
+ * @param \OC\Files\View $view file view
+ * @param $file complete path to file
+ * @param $filename name of file
+ * @param $ext file extension in case a file with the same $filename already exists
+ * @param $location location if file
+ * @param $timestamp deleteion time
+ *
+ * @return size of restored versions
+ */
+ private static function restoreVersions($view, $file, $filename, $ext, $location, $timestamp) {
+ $size = 0;
+ if (\OCP\App::isEnabled('files_versions')) {
+ // disable proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ $user = \OCP\User::getUser();
+ if ($timestamp) {
+ $versionedFile = $filename;
+ } else {
+ $versionedFile = $file;
+ }
+
+ if ($view->is_dir('/files_trashbin/versions/'.$file)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . 'files_trashbin/versions/' . $file));
+ $view->rename(\OC\Files\Filesystem::normalizePath('files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath('files_versions/' . $location . '/' . $filename . $ext));
+ } else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp)) {
+ foreach ($versions as $v) {
+ if ($timestamp) {
+ $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp);
+ $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v);
+ } else {
+ $size += $view->filesize('files_trashbin/versions/' . $versionedFile . '.v' . $v);
+ $view->rename('files_trashbin/versions/' . $versionedFile . '.v' . $v, 'files_versions/' . $location . '/' . $filename . $ext . '.v' . $v);
+ }
+ }
+ }
+
+ // enable proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+ }
+ return $size;
+ }
+
+
+ /**
+ * @brief restore encryption keys from trash bin
+ *
+ * @param \OC\Files\View $view
+ * @param $file complete path to file
+ * @param $filename name of file
+ * @param $ext file extension in case a file with the same $filename already exists
+ * @param $location location if file
+ * @param $timestamp deleteion time
+ *
+ * @return size of restored encrypted file
+ */
+ private static function restoreEncryptionKeys($view, $file, $filename, $ext, $location, $timestamp) {
+ // Take care of encryption keys TODO! Get '.key' in file between file name and delete date (also for permanent delete!)
+ $size = 0;
+ if (\OCP\App::isEnabled('files_encryption')) {
+ $user = \OCP\User::getUser();
+
+ $path_parts = pathinfo($file);
+ $source_location = $path_parts['dirname'];
+
+ if ($view->is_dir('/files_trashbin/keyfiles/'.$file)) {
+ if($source_location != '.') {
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename);
+ $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename);
+ } else {
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename);
+ $sharekey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename);
+ }
+ } else {
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key');
+ }
+
+ if ($timestamp) {
+ $keyfile .= '.d' . $timestamp;
+ }
+
+ // disable proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
+
+ if ($view->file_exists($keyfile)) {
+ // handle directory
+ if ($view->is_dir($keyfile)) {
+
+ // handle keyfiles
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
+ $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext);
+
+ // handle share-keys
+ if ($timestamp) {
+ $sharekey .= '.d' . $timestamp;
+ }
+ $view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext);
+
+ } else {
+ // handle keyfiles
+ $size += $view->filesize($keyfile);
+ $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext . '.key');
+
+ // handle share-keys
+ $ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey');
+ if ($timestamp) {
+ $ownerShareKey .= '.d' . $timestamp;
+ }
+
+ $size += $view->filesize($ownerShareKey);
+
+ // move only owners key
+ $view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext . '.' . $user. '.shareKey');
+
+ // try to re-share if file is shared
+ $filesystemView = new \OC_FilesystemView('/');
+ $session = new \OCA\Encryption\Session($filesystemView);
+ $util = new \OCA\Encryption\Util($filesystemView, $user);
+
+ // fix the file size
+ $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $user . '/files/'. $location. '/' .$filename);
+ $util->fixFileSize($absolutePath);
+
+ // get current sharing state
+ $sharingEnabled = \OCP\Share::isEnabled();
+
+ // get the final filename
+ $target = \OC\Files\Filesystem::normalizePath($location.'/'.$filename);
+
+ // get users sharing this file
+ $usersSharing = $util->getSharingUsersArray($sharingEnabled, $target.$ext, $user);
+
+ // Attempt to set shareKey
+ $util->setSharedFileKeyfiles($session, $usersSharing, $target.$ext);
+ }
+ }
+
+ // enable proxy
+ \OC_FileProxy::$enabled = $proxyStatus;
+ }
+ return $size;
+ }
+
/**
- * delete file from trash bin permanently
+ * @brief delete file from trash bin permanently
+ *
* @param $filename path to the file
* @param $timestamp of deletion time
+ *
* @return size of deleted files
*/
public static function delete($filename, $timestamp=null) {