diff --git a/apps/dav/lib/Connector/Sabre/LockPlugin.php b/apps/dav/lib/Connector/Sabre/LockPlugin.php index 0d5cad6d9a45c..50b31135ba6c8 100644 --- a/apps/dav/lib/Connector/Sabre/LockPlugin.php +++ b/apps/dav/lib/Connector/Sabre/LockPlugin.php @@ -40,6 +40,13 @@ class LockPlugin extends ServerPlugin { */ private $server; + /** + * State of the lock + * + * @var bool + */ + private $isLocked; + /** * {@inheritdoc} */ @@ -66,10 +73,15 @@ public function getLock(RequestInterface $request) { } catch (LockedException $e) { throw new FileLocked($e->getMessage(), $e->getCode(), $e); } + $this->isLocked = true; } } public function releaseLock(RequestInterface $request) { + // don't try to release the lock if we never locked one + if ($this->isLocked === false) { + return; + } if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { return; } @@ -80,6 +92,7 @@ public function releaseLock(RequestInterface $request) { } if ($node instanceof Node) { $node->releaseLock(ILockingProvider::LOCK_SHARED); + $this->isLocked = false; } } } diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php index 6cab64b3a020a..fda48aa46010c 100644 --- a/lib/private/Lock/MemcacheLockingProvider.php +++ b/lib/private/Lock/MemcacheLockingProvider.php @@ -93,8 +93,12 @@ public function acquireLock(string $path, int $type) { */ public function releaseLock(string $path, int $type) { if ($type === self::LOCK_SHARED) { + $ownSharedLockCount = $this->getOwnSharedLockCount($path); $newValue = 0; - if ($this->getOwnSharedLockCount($path) === 1) { + if ($ownSharedLockCount === 0) { // if we are not holding the lock, don't try to release it + return; + } + if ($ownSharedLockCount === 1) { $removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go if (!$removed) { //someone else also has a shared lock, decrease only $newValue = $this->memcache->dec($path);