summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-05-15 10:18:25 +0200
committerFlorin Peter <github@florin-peter.de>2013-05-15 10:18:25 +0200
commit01f1153b0870b8a24586c099131679f992e0d05e (patch)
tree484c32f288c5593d4b646332db1eae382fe762f9 /apps/files_trashbin/lib
parent226aec8d5602e112c413f8c0548b18c737a65a02 (diff)
parent7461e9c2b5bdabd0b712f91a22445a0d933cf88f (diff)
downloadnextcloud-server-01f1153b0870b8a24586c099131679f992e0d05e.tar.gz
nextcloud-server-01f1153b0870b8a24586c099131679f992e0d05e.zip
Merge branch 'files_encryption' of https://github.com/owncloud/core into files_encryption
Conflicts: apps/files/l10n/ar.php apps/files/l10n/bn_BD.php apps/files/l10n/de.php apps/files/l10n/de_DE.php apps/files/l10n/el.php apps/files/l10n/es.php apps/files/l10n/fa.php apps/files/l10n/fr.php apps/files/l10n/gl.php apps/files/l10n/id.php apps/files/l10n/ko.php apps/files/l10n/nl.php apps/files/l10n/nn_NO.php apps/files/l10n/pl.php apps/files/l10n/pt_BR.php apps/files/l10n/pt_PT.php apps/files/l10n/ro.php apps/files/l10n/ru.php apps/files/l10n/sl.php apps/files/l10n/uk.php apps/files/l10n/vi.php apps/files_encryption/l10n/ca.php apps/files_sharing/lib/cache.php apps/files_sharing/lib/sharedstorage.php apps/user_ldap/l10n/tr.php core/l10n/cs_CZ.php core/l10n/de.php core/l10n/de_DE.php core/l10n/ru.php core/l10n/sk_SK.php core/l10n/tr.php core/l10n/vi.php core/l10n/zh_CN.php l10n/af_ZA/files.po l10n/ar/files.po l10n/be/files.po l10n/bg_BG/files.po l10n/bn_BD/files.po l10n/ca/files.po l10n/ca/files_encryption.po l10n/cs_CZ/core.po l10n/cs_CZ/files.po l10n/da/files.po l10n/da/settings.po l10n/de/core.po l10n/de/files.po l10n/de/files_encryption.po l10n/de/files_external.po l10n/de/files_sharing.po l10n/de/files_trashbin.po l10n/de/files_versions.po l10n/de/lib.po l10n/de/settings.po l10n/de/user_ldap.po l10n/de_DE/files.po l10n/de_DE/files_encryption.po l10n/de_DE/files_external.po l10n/de_DE/files_sharing.po l10n/de_DE/files_trashbin.po l10n/de_DE/lib.po l10n/de_DE/settings.po l10n/de_DE/user_ldap.po l10n/el/files.po l10n/eo/files.po l10n/es/files.po l10n/es/lib.po l10n/es/settings.po l10n/es_AR/files.po l10n/eu/files.po l10n/fa/files.po l10n/fi/files.po l10n/fi_FI/files.po l10n/fr/core.po l10n/fr/files.po l10n/gl/files.po l10n/gl/settings.po l10n/he/core.po l10n/he/files.po l10n/he/user_ldap.po l10n/hi/files.po l10n/hr/files.po l10n/hu_HU/core.po l10n/hu_HU/files.po l10n/hu_HU/files_external.po l10n/hu_HU/settings.po l10n/hy/files.po l10n/ia/core.po l10n/ia/files.po l10n/ia/files_trashbin.po l10n/ia/settings.po l10n/id/files.po l10n/is/files.po l10n/it/files.po l10n/ja_JP/files.po l10n/ja_JP/user_ldap.po l10n/ka/files.po l10n/ka_GE/files.po l10n/kn/files.po l10n/ko/files.po l10n/ko/files_trashbin.po l10n/ko/settings.po l10n/ku_IQ/files.po l10n/lb/files.po l10n/lt_LT/core.po l10n/lt_LT/files.po l10n/lv/files.po l10n/mk/files.po l10n/ms_MY/files.po l10n/my_MM/files.po l10n/nb_NO/files.po l10n/ne/files.po l10n/nl/core.po l10n/nl/files.po l10n/nn_NO/files.po l10n/oc/files.po l10n/pl/files.po l10n/pl_PL/files.po l10n/pt_BR/files.po l10n/pt_PT/core.po l10n/pt_PT/files.po l10n/pt_PT/files_external.po l10n/pt_PT/settings.po l10n/ro/files.po l10n/ru/core.po l10n/ru/files.po l10n/si_LK/files.po l10n/sk/files.po l10n/sk_SK/core.po l10n/sk_SK/files.po l10n/sl/core.po l10n/sl/files.po l10n/sq/files.po l10n/sr/files.po l10n/sr@latin/files.po l10n/sv/files.po l10n/sw_KE/files.po l10n/ta_LK/files.po l10n/te/files.po l10n/th_TH/files.po l10n/tr/core.po l10n/tr/files.po l10n/tr/lib.po l10n/tr/settings.po l10n/tr/user_ldap.po l10n/uk/files.po l10n/ur_PK/files.po l10n/vi/core.po l10n/vi/files.po l10n/vi/files_external.po l10n/zh_CN.GB2312/files.po l10n/zh_CN/core.po l10n/zh_CN/files.po l10n/zh_CN/settings.po l10n/zh_HK/files.po l10n/zh_TW/core.po l10n/zh_TW/files.po l10n/zh_TW/files_versions.po l10n/zh_TW/settings.po l10n/zh_TW/user_ldap.po lib/base.php lib/files/filesystem.php lib/files/view.php lib/public/share.php settings/l10n/es.php settings/l10n/pt_PT.php settings/l10n/tr.php settings/l10n/zh_CN.php settings/personal.php
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r--apps/files_trashbin/lib/trash.php190
1 files changed, 122 insertions, 68 deletions
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index 7fda855d0c2..70df9e2426a 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
*
@@ -62,8 +73,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;
@@ -110,13 +125,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);
}
}
@@ -143,35 +162,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');
@@ -186,10 +208,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
@@ -321,6 +343,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 {
@@ -329,15 +357,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);
}
}
}
@@ -356,7 +384,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
@@ -366,20 +394,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) {
@@ -390,35 +423,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('/');
@@ -426,7 +460,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
@@ -475,7 +509,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);
@@ -491,35 +543,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;
}