diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2015-07-07 18:38:58 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2015-07-08 11:32:06 +0200 |
commit | db65eeb5800745fb91cc2056e097c5988155ba20 (patch) | |
tree | ff85a4d6835c7e3bcb8a2090f0e2d4e754f71a84 /apps/files_trashbin/lib | |
parent | 0fe81d2f214c59dbe223e949232475fb8a6f24b9 (diff) | |
download | nextcloud-server-db65eeb5800745fb91cc2056e097c5988155ba20.tar.gz nextcloud-server-db65eeb5800745fb91cc2056e097c5988155ba20.zip |
only move real files to the trash bin
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/storage.php | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php index 006971fb242..4185fc6aec4 100644 --- a/apps/files_trashbin/lib/storage.php +++ b/apps/files_trashbin/lib/storage.php @@ -26,6 +26,7 @@ namespace OCA\Files_Trashbin; use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Wrapper; +use OCP\IUserManager; class Storage extends Wrapper { @@ -41,8 +42,12 @@ class Storage extends Wrapper { */ private static $disableTrash = false; - function __construct($parameters) { + /** @var IUserManager */ + private $userManager; + + function __construct($parameters, IUserManager $userManager = null) { $this->mountPoint = $parameters['mountPoint']; + $this->userManager = $userManager; parent::__construct($parameters); } @@ -101,6 +106,27 @@ class Storage extends Wrapper { } /** + * check if it is a file located in data/user/files only files in the + * 'files' directory should be moved to the trash + * + * @param $path + * @return bool + */ + protected function shouldMoveToTrash($path){ + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); + $parts = explode('/', $normalized); + if (count($parts) < 4) { + return false; + } + + if ($this->userManager->userExists($parts[1]) && $parts[2] == 'files') { + return true; + } + + return false; + } + + /** * Run the delete operation with the given method * * @param string $path path of file or folder to delete @@ -112,6 +138,7 @@ class Storage extends Wrapper { if (self::$disableTrash || !\OC_App::isEnabled('files_trashbin') || (pathinfo($path, PATHINFO_EXTENSION) === 'part') + || $this->shouldMoveToTrash($path) === false ) { return call_user_func_array([$this->storage, $method], [$path]); } @@ -144,7 +171,10 @@ 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)); + return new \OCA\Files_Trashbin\Storage( + array('storage' => $storage, 'mountPoint' => $mountPoint), + \OC::$server->getUserManager() + ); }, 1); } |