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>
This commit is contained in:
Jaakko Salo 2020-05-24 20:03:48 +03:00 committed by backportbot[bot]
parent 392df2eaf4
commit 3f1b055828
1 changed files with 14 additions and 0 deletions

View File

@ -41,6 +41,13 @@ class LockPlugin extends ServerPlugin {
*/ */
private $server; private $server;
/**
* State of the lock
*
* @var bool
*/
private $isLocked;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -48,6 +55,7 @@ class LockPlugin extends ServerPlugin {
$this->server = $server; $this->server = $server;
$this->server->on('beforeMethod:*', [$this, 'getLock'], 50); $this->server->on('beforeMethod:*', [$this, 'getLock'], 50);
$this->server->on('afterMethod:*', [$this, 'releaseLock'], 50); $this->server->on('afterMethod:*', [$this, 'releaseLock'], 50);
$this->isLocked = false;
} }
public function getLock(RequestInterface $request) { public function getLock(RequestInterface $request) {
@ -67,10 +75,15 @@ class LockPlugin extends ServerPlugin {
} catch (LockedException $e) { } catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e); throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} }
$this->isLocked = true;
} }
} }
public function releaseLock(RequestInterface $request) { 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'])) { if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
return; return;
} }
@ -81,6 +94,7 @@ class LockPlugin extends ServerPlugin {
} }
if ($node instanceof Node) { if ($node instanceof Node) {
$node->releaseLock(ILockingProvider::LOCK_SHARED); $node->releaseLock(ILockingProvider::LOCK_SHARED);
$this->isLocked = false;
} }
} }
} }