diff options
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/lib/storage.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 129 | ||||
-rw-r--r-- | apps/files_trashbin/tests/trashbin.php | 14 |
3 files changed, 9 insertions, 138 deletions
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php index 3f474d71da5..61e0816fd24 100644 --- a/apps/files_trashbin/lib/storage.php +++ b/apps/files_trashbin/lib/storage.php @@ -84,7 +84,7 @@ class Storage extends Wrapper { * @param string $path */ public function unlink($path) { - if (self::$disableTrash) { + if (self::$disableTrash || !\OC_App::isEnabled('files_trashbin')) { return $this->storage->unlink($path); } $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); @@ -117,7 +117,7 @@ class Storage extends Wrapper { public static function setupStorage() { \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { return new \OCA\Files_Trashbin\Storage(array('storage' => $storage, 'mountPoint' => $mountPoint)); - }); + }, 1); } } diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 6bdbac49aa7..1c880735b5a 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -183,8 +183,6 @@ class Trashbin { $userTrashSize = self::getTrashbinSize($user); // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp; try { $sizeOfAddedFiles = $view->filesize('/files/' . $file_path); @@ -199,7 +197,6 @@ class Trashbin { } \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR); } - \OC_FileProxy::$enabled = $proxyStatus; if ($view->file_exists('/files/' . $file_path)) { // failed to delete the original file, abort $view->unlink($trashPath); @@ -217,7 +214,6 @@ class Trashbin { 'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp))); $size += self::retainVersions($file_path, $filename, $timestamp); - $size += self::retainEncryptionKeys($file_path, $filename, $timestamp); // if owner !== user we need to also add a copy to the owners trash if ($user !== $owner) { @@ -251,10 +247,6 @@ class Trashbin { $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(); $rootView = new \OC\Files\View('/'); @@ -279,60 +271,12 @@ class Trashbin { $rootView->rename($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/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 string $file_path path to original file - * @param string $filename of deleted file - * @param integer $timestamp when the file was deleted - * - * @return int size of encryption keys - */ - private static function retainEncryptionKeys($file_path, $filename, $timestamp) { - $size = 0; - - if (\OCP\App::isEnabled('files_encryption')) { - - $user = \OCP\User::getUser(); - $rootView = new \OC\Files\View('/'); - - list($owner, $ownerPath) = self::getUidAndFilename($file_path); - - // file has been deleted in between - if (empty($ownerPath)) { - return 0; - } - - $util = new \OCA\Files_Encryption\Util($rootView, $user); - - $baseDir = '/files_encryption/'; - if (!$util->isSystemWideMountPoint($ownerPath)) { - $baseDir = $owner . $baseDir; - } - - $keyfiles = \OC\Files\Filesystem::normalizePath($baseDir . '/keys/' . $ownerPath); - - if ($rootView->is_dir($keyfiles)) { - $size += self::calculateSize(new \OC\Files\View($keyfiles)); - if ($owner !== $user) { - self::copy_recursive($keyfiles, $owner . '/files_trashbin/keys/' . basename($ownerPath) . '.d' . $timestamp, $rootView); - } - $rootView->rename($keyfiles, $user . '/files_trashbin/keys/' . $filename . '.d' . $timestamp); - } - - } - return $size; - } - - /** * restore files from trash bin * * @param string $file path to the deleted file @@ -369,10 +313,6 @@ class Trashbin { $target = \OC\Files\Filesystem::normalizePath('files/' . $location . '/' . $uniqueFilename); $mtime = $view->filemtime($source); - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; - // restore file $restoreResult = $view->rename($source, $target); @@ -386,22 +326,15 @@ class Trashbin { 'trashPath' => \OC\Files\Filesystem::normalizePath($file))); self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp); - self::restoreEncryptionKeys($view, $file, $filename, $uniqueFilename, $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)); } - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - return true; } - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - return false; } @@ -419,9 +352,6 @@ class Trashbin { private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) { if (\OCP\App::isEnabled('files_versions')) { - // disable proxy to prevent recursive calls - $proxyStatus = \OC_FileProxy::$enabled; - \OC_FileProxy::$enabled = false; $user = \OCP\User::getUser(); $rootView = new \OC\Files\View('/'); @@ -432,7 +362,6 @@ class Trashbin { // file has been deleted in between if (empty($ownerPath)) { - \OC_FileProxy::$enabled = $proxyStatus; return false; } @@ -453,63 +382,6 @@ class Trashbin { } } } - - // enable proxy - \OC_FileProxy::$enabled = $proxyStatus; - } - } - - /** - * restore encryption keys from trash bin - * - * @param \OC\Files\View $view - * @param string $file complete path to file - * @param string $filename name of file - * @param string $uniqueFilename new file name to restore the file without overwriting existing files - * @param string $location location of file - * @param int $timestamp deletion time - * @return bool - */ - private static function restoreEncryptionKeys(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) { - - if (\OCP\App::isEnabled('files_encryption')) { - $user = \OCP\User::getUser(); - $rootView = new \OC\Files\View('/'); - - $target = \OC\Files\Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename); - - list($owner, $ownerPath) = self::getUidAndFilename($target); - - // file has been deleted in between - if (empty($ownerPath)) { - return false; - } - - $util = new \OCA\Files_Encryption\Util($rootView, $user); - - $baseDir = '/files_encryption/'; - if (!$util->isSystemWideMountPoint($ownerPath)) { - $baseDir = $owner . $baseDir; - } - - $source_location = dirname($file); - - if ($view->is_dir('/files_trashbin/keys/' . $file)) { - if ($source_location != '.') { - $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keys/' . $source_location . '/' . $filename); - } else { - $keyfile = \OC\Files\Filesystem::normalizePath($user . '/files_trashbin/keys/' . $filename); - } - } - - if ($timestamp) { - $keyfile .= '.d' . $timestamp; - } - - if ($rootView->is_dir($keyfile)) { - $rootView->rename($keyfile, $baseDir . '/keys/' . $ownerPath); - } - } } @@ -528,7 +400,6 @@ class Trashbin { return true; } - /** * delete file from trash bin permanently * diff --git a/apps/files_trashbin/tests/trashbin.php b/apps/files_trashbin/tests/trashbin.php index b3176ebbe92..bf6446389f1 100644 --- a/apps/files_trashbin/tests/trashbin.php +++ b/apps/files_trashbin/tests/trashbin.php @@ -26,7 +26,7 @@ use OCA\Files_Trashbin; /** - * Class Test_Encryption_Crypt + * Class Test_Encryption */ class Test_Trashbin extends \Test\TestCase { @@ -36,7 +36,6 @@ class Test_Trashbin extends \Test\TestCase { private $trashRoot1; private $trashRoot2; - private static $encryptionStatus; private static $rememberRetentionObligation; private static $rememberAutoExpire; @@ -58,7 +57,6 @@ class Test_Trashbin extends \Test\TestCase { \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); //disable encryption - self::$encryptionStatus = \OC_App::isEnabled('files_encryption'); \OC_App::disable('files_encryption'); //configure trashbin @@ -82,10 +80,6 @@ class Test_Trashbin extends \Test\TestCase { // cleanup test user \OC_User::deleteUser(self::TEST_TRASHBIN_USER1); - if (self::$encryptionStatus === true) { - \OC_App::enable('files_encryption'); - } - \OC_Config::setValue('trashbin_retention_obligation', self::$rememberRetentionObligation); \OC_Config::setValue('trashbin_auto_expire', self::$rememberAutoExpire); @@ -312,6 +306,12 @@ class Test_Trashbin extends \Test\TestCase { } } + $storage = new \ReflectionClass('\OC\Files\Storage\Shared'); + $isInitialized = $storage->getProperty('isInitialized'); + $isInitialized->setAccessible(true); + $isInitialized->setValue(array()); + $isInitialized->setAccessible(false); + \OC_Util::tearDownFS(); \OC_User::setUserId(''); \OC\Files\Filesystem::tearDown(); |