diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-07-06 22:52:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-06 22:52:46 +0200 |
commit | 42d899c4d5f4fdc369071c409376200d95f7b4ad (patch) | |
tree | ea03867725934a97436c4708432db22cf1f9163e | |
parent | 341757945fb9d0878e2bbefc3db967570e712c57 (diff) | |
parent | 3f1b055828253c10b4e17558c3daf91270a1bdfe (diff) | |
download | nextcloud-server-42d899c4d5f4fdc369071c409376200d95f7b4ad.tar.gz nextcloud-server-42d899c4d5f4fdc369071c409376200d95f7b4ad.zip |
Merge pull request #21710 from nextcloud/backport/21074/stable19
[stable19] Fix releasing a shared lock multiple times
-rw-r--r-- | apps/dav/lib/Connector/Sabre/LockPlugin.php | 14 | ||||
-rw-r--r-- | lib/private/Lock/MemcacheLockingProvider.php | 6 |
2 files changed, 19 insertions, 1 deletions
diff --git a/apps/dav/lib/Connector/Sabre/LockPlugin.php b/apps/dav/lib/Connector/Sabre/LockPlugin.php index 7c07f45fc79..bdb681be8da 100644 --- a/apps/dav/lib/Connector/Sabre/LockPlugin.php +++ b/apps/dav/lib/Connector/Sabre/LockPlugin.php @@ -42,12 +42,20 @@ class LockPlugin extends ServerPlugin { private $server; /** + * State of the lock + * + * @var bool + */ + private $isLocked; + + /** * {@inheritdoc} */ public function initialize(\Sabre\DAV\Server $server) { $this->server = $server; $this->server->on('beforeMethod:*', [$this, 'getLock'], 50); $this->server->on('afterMethod:*', [$this, 'releaseLock'], 50); + $this->isLocked = false; } public function getLock(RequestInterface $request) { @@ -67,10 +75,15 @@ class LockPlugin extends ServerPlugin { } 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; } @@ -81,6 +94,7 @@ class LockPlugin extends ServerPlugin { } 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 3d7510f43ff..bff4eabbbd8 100644 --- a/lib/private/Lock/MemcacheLockingProvider.php +++ b/lib/private/Lock/MemcacheLockingProvider.php @@ -94,8 +94,12 @@ class MemcacheLockingProvider extends AbstractLockingProvider { */ 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); |