From 62bc53143e7f6b13fad1d0bb9e899a3715d55e49 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 9 Mar 2016 09:11:41 +0100 Subject: Add locking to modifying operation of the OCS Share API Fixes #17243 This is done in the OCS Share API instead of the share manager since we want lazy shares in general. However when doing modifying calls via the OCS Share API it is fine to force real nodes. * Updated unit tests to work with logging --- apps/files_sharing/api/share20ocs.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'apps/files_sharing/api') diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index 68098530017..8b2c413b6fc 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -28,6 +28,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\Files\IRootFolder; +use OCP\Lock\LockedException; use OCP\Share; use OCP\Share\IManager; @@ -205,12 +206,20 @@ class Share20OCS { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } + try { + $share->getNode()->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + } catch (LockedException $e) { + return new \OC_OCS_Result(null, 404, 'could not delete share'); + } + if (!$this->canAccessShare($share)) { return new \OC_OCS_Result(null, 404, $this->l->t('Could not delete share')); } $this->shareManager->deleteShare($share); + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + return new \OC_OCS_Result(); } @@ -238,6 +247,7 @@ class Share20OCS { } $share->setNode($path); + $share->getNode()->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED); // Parse permissions (if available) $permissions = $this->request->getParam('permissions', null); @@ -368,8 +378,11 @@ class Share20OCS { return new \OC_OCS_Result(null, 403, $e->getMessage()); } - $share = $this->formatShare($share); - return new \OC_OCS_Result($share); + $output = $this->formatShare($share); + + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + + return new \OC_OCS_Result($output); } /** @@ -512,6 +525,8 @@ class Share20OCS { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } + $share->getNode()->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + if (!$this->canAccessShare($share)) { return new \OC_OCS_Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist')); } @@ -611,6 +626,8 @@ class Share20OCS { return new \OC_OCS_Result(null, 400, $e->getMessage()); } + $share->getNode()->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED); + return new \OC_OCS_Result($this->formatShare($share)); } -- cgit v1.2.3