aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaakko Salo <jaakkos@gmail.com>2020-05-24 20:03:48 +0300
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2020-07-06 12:11:47 +0000
commit3f1b055828253c10b4e17558c3daf91270a1bdfe (patch)
tree103ad21e77da6afb8481b1632a4003ad28661369
parent392df2eaf4ae41530b4743305a765a7ec173e92a (diff)
downloadnextcloud-server-3f1b055828253c10b4e17558c3daf91270a1bdfe.tar.gz
nextcloud-server-3f1b055828253c10b4e17558c3daf91270a1bdfe.zip
In LockPlugin, only release a lock if it was acquired
When uploading new files, getNodeForPath() will not succeed yet so the lock cannot be acquired. In that case, don't try to unlock it either. Signed-off-by: Jaakko Salo <jaakkos@gmail.com>
-rw-r--r--apps/dav/lib/Connector/Sabre/LockPlugin.php14
1 files changed, 14 insertions, 0 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;
}
}
}