Skip to content

Commit

Permalink
In LockPlugin, only release a lock if it was acquired
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jvsalo authored and backportbot[bot] committed Jul 6, 2020
1 parent 392df2e commit 3f1b055
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/dav/lib/Connector/Sabre/LockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ 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) {
Expand All @@ -67,10 +75,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;
}
Expand All @@ -81,6 +94,7 @@ public function releaseLock(RequestInterface $request) {
}
if ($node instanceof Node) {
$node->releaseLock(ILockingProvider::LOCK_SHARED);
$this->isLocked = false;
}
}
}

0 comments on commit 3f1b055

Please sign in to comment.