From d9a37cad645bfd745293377123edf508de5ce8a9 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 22 Nov 2019 09:55:59 -0100 Subject: [PATCH] returns LockedException on UPDATE & DELETE --- lib/Storage/LockWrapper.php | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/Storage/LockWrapper.php b/lib/Storage/LockWrapper.php index e220ac1e..eeba4069 100644 --- a/lib/Storage/LockWrapper.php +++ b/lib/Storage/LockWrapper.php @@ -26,6 +26,7 @@ use OCP\Constants; use OCP\Files\InvalidPathException; use OCP\IUserSession; +use OCP\Lock\LockedException; class LockWrapper extends Wrapper { /** @var LockService */ @@ -40,7 +41,38 @@ public function __construct($arguments) { $this->userSession = $arguments['user_session']; } - protected function checkPermissions($path, $permissions) { + + /** + * @param $path + * @param $permissions + * + * @return bool + * @throws LockedException + */ + protected function checkPermissions($path, $permissions): bool { + if (!$this->isLocked($path)) { + return true; + } + + \OC::$server->getLogger() + ->log(3, '---- ' . $permissions); + switch ($permissions) { + case Constants::PERMISSION_DELETE: + case Constants::PERMISSION_UPDATE: + throw new LockedException($path); + + default: + return false; + } + + } + + /** + * @param $path + * + * @return bool + */ + protected function isLocked($path): bool { try { $user = $this->userSession->getUser(); $userId = ''; @@ -48,13 +80,14 @@ protected function checkPermissions($path, $permissions) { $userId = $user->getUID(); } - return !$this->lockService->isPathLocked($path, $userId); + return $this->lockService->isPathLocked($path, $userId); } catch (InvalidPathException $e) { } - return true; + return false; } + public function rename($path1, $path2) { if (strpos($path1, $path2) === 0) { $part = substr($path1, strlen($path2));