summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/appinfo/app.php6
-rw-r--r--apps/files_trashbin/js/trash.js2
-rw-r--r--apps/files_trashbin/l10n/bg_BG.php2
-rw-r--r--apps/files_trashbin/l10n/he.php17
-rw-r--r--apps/files_trashbin/l10n/ko.php1
-rw-r--r--apps/files_trashbin/l10n/lt_LT.php11
-rw-r--r--apps/files_trashbin/l10n/nb_NO.php3
-rw-r--r--apps/files_trashbin/l10n/nn_NO.php10
-rw-r--r--apps/files_trashbin/l10n/ru_RU.php15
-rw-r--r--apps/files_trashbin/l10n/ug.php11
-rw-r--r--apps/files_trashbin/lib/trash.php206
11 files changed, 184 insertions, 100 deletions
diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php
index e83d3b8fbbd..3b1e0ac30cc 100644
--- a/apps/files_trashbin/appinfo/app.php
+++ b/apps/files_trashbin/appinfo/app.php
@@ -3,7 +3,5 @@
OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'files_trashbin/lib/hooks.php';
OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'files_trashbin/lib/trash.php';
-//Listen to delete file signal
-OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Trashbin\Hooks", "remove_hook");
-//Listen to delete user signal
-OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Trashbin\Hooks", "deleteUser_hook"); \ No newline at end of file
+// register hooks
+\OCA\Files_Trashbin\Trashbin::registerHooks(); \ No newline at end of file
diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js
index eed253d6602..691642811b7 100644
--- a/apps/files_trashbin/js/trash.js
+++ b/apps/files_trashbin/js/trash.js
@@ -93,6 +93,7 @@ $(document).ready(function() {
});
$('.undelete').click('click',function(event) {
+ event.preventDefault();
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loader.gif') +'"></a>';
var files=getSelectedFiles('file');
var fileslist = JSON.stringify(files);
@@ -117,6 +118,7 @@ $(document).ready(function() {
});
$('.delete').click('click',function(event) {
+ event.preventDefault();
console.log("delete selected");
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'Delete permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
var files=getSelectedFiles('file');
diff --git a/apps/files_trashbin/l10n/bg_BG.php b/apps/files_trashbin/l10n/bg_BG.php
index 288518e1a41..1e0953b013a 100644
--- a/apps/files_trashbin/l10n/bg_BG.php
+++ b/apps/files_trashbin/l10n/bg_BG.php
@@ -1,5 +1,5 @@
<?php $TRANSLATIONS = array(
-"Couldn't delete %s permanently" => "Невъзможно изтриване на %s завинаги",
+"Couldn't delete %s permanently" => "Невъзможно перманентното изтриване на %s",
"Couldn't restore %s" => "Невъзможно възтановяване на %s",
"perform restore operation" => "извършване на действие по възстановяване",
"Error" => "Грешка",
diff --git a/apps/files_trashbin/l10n/he.php b/apps/files_trashbin/l10n/he.php
index e31fdb952ea..853d4e1925a 100644
--- a/apps/files_trashbin/l10n/he.php
+++ b/apps/files_trashbin/l10n/he.php
@@ -1,17 +1,18 @@
<?php $TRANSLATIONS = array(
-"Couldn't delete %s permanently" => "בלתי אפשרי למחוק את %s לצמיתות",
-"Couldn't restore %s" => "בלתי אפשרי לשחזר את %s",
-"perform restore operation" => "בצע פעולת שחזור",
+"Couldn't delete %s permanently" => "לא ניתן למחוק את %s לצמיתות",
+"Couldn't restore %s" => "לא ניתן לשחזר את %s",
+"perform restore operation" => "ביצוע פעולת שחזור",
"Error" => "שגיאה",
-"delete file permanently" => "מחק קובץ לצמיתות",
-"Delete permanently" => "מחק לצמיתות",
+"delete file permanently" => "מחיקת קובץ לצמיתות",
+"Delete permanently" => "מחיקה לצמיתות",
"Name" => "שם",
"Deleted" => "נמחק",
"1 folder" => "תיקייה אחת",
"{count} folders" => "{count} תיקיות",
"1 file" => "קובץ אחד",
"{count} files" => "{count} קבצים",
-"Nothing in here. Your trash bin is empty!" => "שום דבר כאן. סל המחזור שלך ריק!",
-"Restore" => "שחזר",
-"Delete" => "מחיקה"
+"Nothing in here. Your trash bin is empty!" => "אין כאן שום דבר. סל המיחזור שלך ריק!",
+"Restore" => "שחזור",
+"Delete" => "מחיקה",
+"Deleted Files" => "קבצים שנמחקו"
);
diff --git a/apps/files_trashbin/l10n/ko.php b/apps/files_trashbin/l10n/ko.php
index f06c90962ea..42ad87e98d2 100644
--- a/apps/files_trashbin/l10n/ko.php
+++ b/apps/files_trashbin/l10n/ko.php
@@ -1,5 +1,6 @@
<?php $TRANSLATIONS = array(
"Error" => "오류",
+"Delete permanently" => "영원히 삭제",
"Name" => "이름",
"1 folder" => "폴더 1개",
"{count} folders" => "폴더 {count}개",
diff --git a/apps/files_trashbin/l10n/lt_LT.php b/apps/files_trashbin/l10n/lt_LT.php
index 011de161e42..7df63bd7f28 100644
--- a/apps/files_trashbin/l10n/lt_LT.php
+++ b/apps/files_trashbin/l10n/lt_LT.php
@@ -1,9 +1,18 @@
<?php $TRANSLATIONS = array(
+"Couldn't delete %s permanently" => "Nepavyko negrįžtamai ištrinti %s",
+"Couldn't restore %s" => "Nepavyko atkurti %s",
+"perform restore operation" => "atkurti",
"Error" => "Klaida",
+"delete file permanently" => "failą ištrinti negrįžtamai",
+"Delete permanently" => "Ištrinti negrįžtamai",
"Name" => "Pavadinimas",
+"Deleted" => "Ištrinti",
"1 folder" => "1 aplankalas",
"{count} folders" => "{count} aplankalai",
"1 file" => "1 failas",
"{count} files" => "{count} failai",
-"Delete" => "Ištrinti"
+"Nothing in here. Your trash bin is empty!" => "Nieko nėra. Jūsų šiukšliadėžė tuščia!",
+"Restore" => "Atstatyti",
+"Delete" => "Ištrinti",
+"Deleted Files" => "Ištrinti failai"
);
diff --git a/apps/files_trashbin/l10n/nb_NO.php b/apps/files_trashbin/l10n/nb_NO.php
index e1dce4b3995..43ad0180494 100644
--- a/apps/files_trashbin/l10n/nb_NO.php
+++ b/apps/files_trashbin/l10n/nb_NO.php
@@ -13,5 +13,6 @@
"{count} files" => "{count} filer",
"Nothing in here. Your trash bin is empty!" => "Ingenting her. Søppelkassen din er tom!",
"Restore" => "Gjenopprett",
-"Delete" => "Slett"
+"Delete" => "Slett",
+"Deleted Files" => "Slettet filer"
);
diff --git a/apps/files_trashbin/l10n/nn_NO.php b/apps/files_trashbin/l10n/nn_NO.php
index 8166a024e58..454ea2b0575 100644
--- a/apps/files_trashbin/l10n/nn_NO.php
+++ b/apps/files_trashbin/l10n/nn_NO.php
@@ -1,10 +1,18 @@
<?php $TRANSLATIONS = array(
+"Couldn't delete %s permanently" => "Klarte ikkje sletta %s for godt",
+"Couldn't restore %s" => "Klarte ikkje gjenoppretta %s",
+"perform restore operation" => "utfør gjenoppretting",
"Error" => "Feil",
+"delete file permanently" => "slett fila for godt",
"Delete permanently" => "Slett for godt",
"Name" => "Namn",
+"Deleted" => "Sletta",
"1 folder" => "1 mappe",
"{count} folders" => "{count} mapper",
"1 file" => "1 fil",
"{count} files" => "{count} filer",
-"Delete" => "Slett"
+"Nothing in here. Your trash bin is empty!" => "Ingenting her. Papirkorga di er tom!",
+"Restore" => "Gjenopprett",
+"Delete" => "Slett",
+"Deleted Files" => "Sletta filer"
);
diff --git a/apps/files_trashbin/l10n/ru_RU.php b/apps/files_trashbin/l10n/ru_RU.php
index 178eb531077..8636e417ecb 100644
--- a/apps/files_trashbin/l10n/ru_RU.php
+++ b/apps/files_trashbin/l10n/ru_RU.php
@@ -1,18 +1,5 @@
<?php $TRANSLATIONS = array(
-"Couldn't delete %s permanently" => "%s не может быть удалён навсегда",
-"Couldn't restore %s" => "%s не может быть восстановлен",
-"perform restore operation" => "выполнить операцию восстановления",
"Error" => "Ошибка",
-"delete file permanently" => "удалить файл навсегда",
-"Delete permanently" => "Удалить навсегда",
"Name" => "Имя",
-"Deleted" => "Удалён",
-"1 folder" => "1 папка",
-"{count} folders" => "{количество} папок",
-"1 file" => "1 файл",
-"{count} files" => "{количество} файлов",
-"Nothing in here. Your trash bin is empty!" => "Здесь ничего нет. Ваша корзина пуста!",
-"Restore" => "Восстановить",
-"Delete" => "Удалить",
-"Deleted Files" => "Удаленные файлы"
+"Delete" => "Удалить"
);
diff --git a/apps/files_trashbin/l10n/ug.php b/apps/files_trashbin/l10n/ug.php
new file mode 100644
index 00000000000..c369e385f74
--- /dev/null
+++ b/apps/files_trashbin/l10n/ug.php
@@ -0,0 +1,11 @@
+<?php $TRANSLATIONS = array(
+"Error" => "خاتالىق",
+"Delete permanently" => "مەڭگۈلۈك ئۆچۈر",
+"Name" => "ئاتى",
+"Deleted" => "ئۆچۈرۈلدى",
+"1 folder" => "1 قىسقۇچ",
+"1 file" => "1 ھۆججەت",
+"{count} files" => "{count} ھۆججەت",
+"Nothing in here. Your trash bin is empty!" => "بۇ جايدا ھېچنېمە يوق. Your trash bin is empty!",
+"Delete" => "ئۆچۈر"
+);
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index 69adf08dd40..7b8d3cb4252 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -29,6 +29,17 @@ class Trashbin {
// unit: percentage; 50% of available disk space/quota
const DEFAULTMAXSIZE=50;
+ public static function getUidAndFilename($filename) {
+ $uid = \OC\Files\Filesystem::getOwner($filename);
+ \OC\Files\Filesystem::initMountPoints($uid);
+ if ( $uid != \OCP\User::getUser() ) {
+ $info = \OC\Files\Filesystem::getFileInfo($filename);
+ $ownerView = new \OC\Files\View('/'.$uid.'/files');
+ $filename = $ownerView->getPath($info['fileid']);
+ }
+ return array($uid, $filename);
+ }
+
/**
* move file to the trash bin
*
@@ -69,8 +80,12 @@ class Trashbin {
if ( $trashbinSize === false || $trashbinSize < 0 ) {
$trashbinSize = self::calculateSize(new \OC\Files\View('/'. $user.'/files_trashbin'));
}
-
+
+ // disable proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
$sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/'.$filename.'.d'.$timestamp, $view);
+ \OC_FileProxy::$enabled = $proxyStatus;
if ( $view->file_exists('files_trashbin/files/'.$filename.'.d'.$timestamp) ) {
$trashbinSize += $sizeOfAddedFiles;
@@ -117,13 +132,17 @@ class Trashbin {
\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)) {
+ $rootView = new \OC\Files\View('/');
+
+ list($owner, $ownerPath) = self::getUidAndFilename($file_path);
+
+ if ($rootView->is_dir($owner.'/files_versions/' . $ownerPath)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $owner . '/files_versions/' . $ownerPath));
+ $rootView->rename($owner.'/files_versions/' . $ownerPath, $user.'/files_trashbin/versions/' . $filename . '.d' . $timestamp);
+ } else if ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) {
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);
+ $size += $rootView->filesize($owner.'/files_versions' . $v['path'] . '.v' . $v['version']);
+ $rootView->rename($owner.'/files_versions' . $v['path'] . '.v' . $v['version'], $user.'/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp);
}
}
@@ -150,35 +169,38 @@ class Trashbin {
if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser();
+ $rootView = new \OC\Files\View('/');
+
+ list($owner, $ownerPath) = self::getUidAndFilename($file_path);
+
// 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);
+ $keyfile = \OC\Files\Filesystem::normalizePath($owner.'/files_encryption/keyfiles/' . $ownerPath);
- if ($view->is_dir($keyfile) || $view->file_exists($keyfile . '.key')) {
- $user = \OCP\User::getUser();
+ if ($rootView->is_dir($keyfile) || $rootView->file_exists($keyfile . '.key')) {
// 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);
+ if ($rootView->is_dir($keyfile)) {
+ $size += self::calculateSize(new \OC\Files\View($keyfile));
+ $rootView->rename($keyfile, $user.'/files_trashbin/keyfiles/' . $filename . '.d' . $timestamp);
} else {
- $size += $view->filesize($keyfile . '.key');
- $view->rename($keyfile . '.key', 'files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp);
+ $size += $rootView->filesize($keyfile . '.key');
+ $rootView->rename($keyfile . '.key', $user.'/files_trashbin/keyfiles/' . $filename . '.key.d' . $timestamp);
}
}
// retain share keys
- $sharekeys = \OC\Files\Filesystem::normalizePath('files_encryption/share-keys/' . $file_path);
+ $sharekeys = \OC\Files\Filesystem::normalizePath($owner.'/files_encryption/share-keys/' . $ownerPath);
- if ($view->is_dir($sharekeys)) {
- $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys));
- $view->rename($sharekeys, 'files_trashbin/share-keys/' . $filename . '.d' . $timestamp);
+ if ($rootView->is_dir($sharekeys)) {
+ $size += self::calculateSize(new \OC\Files\View($sharekeys));
+ $rootView->rename($sharekeys, $user.'/files_trashbin/share-keys/' . $filename . '.d' . $timestamp);
} else {
// get local path to share-keys
- $localShareKeysPath = $view->getLocalFile($sharekeys);
+ $localShareKeysPath = $rootView->getLocalFile($sharekeys);
// handle share-keys
$matches = glob(preg_quote($localShareKeysPath).'*.shareKey');
@@ -193,10 +215,10 @@ class Trashbin {
if($pathinfo['basename'] == $ownerShareKey) {
// calculate size
- $size += $view->filesize($sharekeys. '.' . $user. '.shareKey');
+ $size += $rootView->filesize($sharekeys. '.' . $user. '.shareKey');
// move file
- $view->rename($sharekeys. '.' . $user. '.shareKey', 'files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp);
+ $rootView->rename($sharekeys. '.' . $user. '.shareKey', $user.'/files_trashbin/share-keys/' . $ownerShareKey . '.d' . $timestamp);
} else {
// calculate size
@@ -273,7 +295,10 @@ class Trashbin {
// handle the restore result
if( $restoreResult ) {
- $view->touch($target.$ext, $mtime);
+ $fakeRoot = $view->getRoot();
+ $view->chroot('/'.$user.'/files');
+ $view->touch('/'.$location.'/'.$filename.$ext, $mtime);
+ $view->chroot($fakeRoot);
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore',
array('filePath' => \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext),
'trashPath' => \OC\Files\Filesystem::normalizePath($file)));
@@ -325,6 +350,12 @@ class Trashbin {
\OC_FileProxy::$enabled = false;
$user = \OCP\User::getUser();
+ $rootView = new \OC\Files\View('/');
+
+ $target = \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext);
+
+ list($owner, $ownerPath) = self::getUidAndFilename($target);
+
if ($timestamp) {
$versionedFile = $filename;
} else {
@@ -333,15 +364,15 @@ class Trashbin {
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));
+ $rootView->rename(\OC\Files\Filesystem::normalizePath($user.'/files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath($owner.'/files_versions/' . $ownerPath));
} 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);
+ $rootView->rename($user.'/files_trashbin/versions/' . $versionedFile . '.v' . $v . '.d' . $timestamp, $owner.'/files_versions/' . $ownerPath . '.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);
+ $rootView->rename($user.'/files_trashbin/versions/' . $versionedFile . '.v' . $v, $owner.'/files_versions/' . $ownerPath . '.v' . $v);
}
}
}
@@ -360,7 +391,7 @@ class Trashbin {
* @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 $location location of file
* @param $timestamp deleteion time
*
* @return size of restored encrypted file
@@ -370,20 +401,25 @@ class Trashbin {
$size = 0;
if (\OCP\App::isEnabled('files_encryption')) {
$user = \OCP\User::getUser();
+ $rootView = new \OC\Files\View('/');
+
+ $target = \OC\Files\Filesystem::normalizePath('/'.$location.'/'.$filename.$ext);
+
+ list($owner, $ownerPath) = self::getUidAndFilename($target);
$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);
+ $keyfile = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/keyfiles/' . $source_location . '/' . $filename);
+ $sharekey = \OC\Files\Filesystem::normalizePath($user.'/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);
+ $keyfile = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/keyfiles/' . $filename);
+ $sharekey = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/share-keys/' . $filename);
}
} else {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key');
+ $keyfile = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/keyfiles/' . $source_location . '/' . $filename . '.key');
}
if ($timestamp) {
@@ -394,35 +430,36 @@ class Trashbin {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
- if ($view->file_exists($keyfile)) {
+ if ($rootView->file_exists($keyfile)) {
// handle directory
- if ($view->is_dir($keyfile)) {
+ if ($rootView->is_dir($keyfile)) {
// handle keyfiles
- $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
- $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext);
+ $size += self::calculateSize(new \OC\Files\View($keyfile));
+ $rootView->rename($keyfile, $owner.'/files_encryption/keyfiles/' . $ownerPath);
// handle share-keys
if ($timestamp) {
$sharekey .= '.d' . $timestamp;
}
- $view->rename($sharekey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext);
+ $size += self::calculateSize(new \OC\Files\View($sharekey));
+ $rootView->rename($sharekey, $owner.'/files_encryption/share-keys/' . $ownerPath);
} else {
// handle keyfiles
- $size += $view->filesize($keyfile);
- $view->rename($keyfile, 'files_encryption/keyfiles/' . $location . '/' . $filename . $ext . '.key');
+ $size += $rootView->filesize($keyfile);
+ $rootView->rename($keyfile, $owner.'/files_encryption/keyfiles/' . $ownerPath . '.key');
// handle share-keys
- $ownerShareKey = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey');
+ $ownerShareKey = \OC\Files\Filesystem::normalizePath($user.'/files_trashbin/share-keys/' . $source_location . '/' . $filename . '.' . $user. '.shareKey');
if ($timestamp) {
$ownerShareKey .= '.d' . $timestamp;
}
- $size += $view->filesize($ownerShareKey);
+ $size += $rootView->filesize($ownerShareKey);
// move only owners key
- $view->rename($ownerShareKey, 'files_encryption/share-keys/' . $location . '/' . $filename . $ext . '.' . $user. '.shareKey');
+ $rootView->rename($ownerShareKey, $owner.'/files_encryption/share-keys/' . $ownerPath . '.' . $user. '.shareKey');
// try to re-share if file is shared
$filesystemView = new \OC_FilesystemView('/');
@@ -430,7 +467,7 @@ class Trashbin {
$util = new \OCA\Encryption\Util($filesystemView, $user);
// fix the file size
- $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $user . '/files/'. $location. '/' .$filename);
+ $absolutePath = \OC\Files\Filesystem::normalizePath('/' . $owner . '/files/'. $ownerPath);
$util->fixFileSize($absolutePath);
// get current sharing state
@@ -479,7 +516,25 @@ class Trashbin {
$file = $filename;
}
+ $size += self::deleteVersions($view, $file, $filename, $timestamp);
+ $size += self::deleteEncryptionKeys($view, $file, $filename, $timestamp);
+
+ if ($view->is_dir('/files_trashbin/files/'.$file)) {
+ $size += self::calculateSize(new \OC\Files\View('/'.$user.'/files_trashbin/files/'.$file));
+ } else {
+ $size += $view->filesize('/files_trashbin/files/'.$file);
+ }
+ $view->unlink('/files_trashbin/files/'.$file);
+ $trashbinSize -= $size;
+ self::setTrashbinSize($user, $trashbinSize);
+
+ return $size;
+ }
+
+ private static function deleteVersions($view, $file, $filename, $timestamp) {
+ $size = 0;
if ( \OCP\App::isEnabled('files_versions') ) {
+ $user = \OCP\User::getUser();
if ($view->is_dir('files_trashbin/versions/'.$file)) {
$size += self::calculateSize(new \OC\Files\view('/'.$user.'/files_trashbin/versions/'.$file));
$view->unlink('files_trashbin/versions/'.$file);
@@ -495,35 +550,37 @@ class Trashbin {
}
}
}
-
- // Take care of encryption keys
- $parts = pathinfo($file);
- if ( $view->is_dir('/files_trashbin/files/'.$file) ) {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename);
- } else {
- $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename.'.key');
- }
- if ($timestamp) {
- $keyfile .= '.d'.$timestamp;
- }
- if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) {
- if ( $view->is_dir($keyfile) ) {
- $size += self::calculateSize(new \OC\Files\View('/'.$user.'/'.$keyfile));
+ return $size;
+ }
+
+ private static function deleteEncryptionKeys($view, $file, $filename, $timestamp) {
+ $size = 0;
+ if (\OCP\App::isEnabled('files_encryption')) {
+ $user = \OCP\User::getUser();
+
+ if ($view->is_dir('/files_trashbin/files/' . $file)) {
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename);
+ $sharekeys = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename);
} else {
- $size += $view->filesize($keyfile);
+ $keyfile = \OC\Files\Filesystem::normalizePath('files_trashbin/keyfiles/' . $filename . '.key');
+ $sharekeys = \OC\Files\Filesystem::normalizePath('files_trashbin/share-keys/' . $filename . '.' . $user . '.shareKey');
+ }
+ if ($timestamp) {
+ $keyfile .= '.d' . $timestamp;
+ $sharekeys .= '.d' . $timestamp;
+ }
+ if ($view->file_exists($keyfile)) {
+ if ($view->is_dir($keyfile)) {
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $keyfile));
+ $size += self::calculateSize(new \OC\Files\View('/' . $user . '/' . $sharekeys));
+ } else {
+ $size += $view->filesize($keyfile);
+ $size += $view->filesize($sharekeys);
+ }
+ $view->unlink($keyfile);
+ $view->unlink($sharekeys);
}
- $view->unlink($keyfile);
- }
-
- if ($view->is_dir('/files_trashbin/files/'.$file)) {
- $size += self::calculateSize(new \OC\Files\View('/'.$user.'/files_trashbin/files/'.$file));
- } else {
- $size += $view->filesize('/files_trashbin/files/'.$file);
}
- $view->unlink('/files_trashbin/files/'.$file);
- $trashbinSize -= $size;
- self::setTrashbinSize($user, $trashbinSize);
-
return $size;
}
@@ -783,5 +840,14 @@ class Trashbin {
}
$query->execute(array($size, $user));
}
-
+
+ /**
+ * register hooks
+ */
+ public static function registerHooks() {
+ //Listen to delete file signal
+ \OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Trashbin\Hooks", "remove_hook");
+ //Listen to delete user signal
+ \OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Trashbin\Hooks", "deleteUser_hook");
+ }
}