aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Files/Lock/LockManager.php41
-rw-r--r--lib/public/Files/Lock/ILockManager.php8
2 files changed, 41 insertions, 8 deletions
diff --git a/lib/private/Files/Lock/LockManager.php b/lib/private/Files/Lock/LockManager.php
index e2af532a01c..26fdeb38578 100644
--- a/lib/private/Files/Lock/LockManager.php
+++ b/lib/private/Files/Lock/LockManager.php
@@ -7,8 +7,11 @@ use OCP\Files\Lock\ILockManager;
use OCP\Files\Lock\ILockProvider;
use OCP\Files\Lock\LockContext;
use OCP\PreConditionNotMetException;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
class LockManager implements ILockManager {
+ private ?string $lockProviderClass = null;
private ?ILockProvider $lockProvider = null;
private ?LockContext $lockInScope = null;
@@ -20,12 +23,34 @@ class LockManager implements ILockManager {
$this->lockProvider = $lockProvider;
}
+ public function registerLazyLockProvider(string $lockProviderClass): void {
+ if ($this->lockProviderClass || $this->lockProvider) {
+ throw new PreConditionNotMetException('There is already a registered lock provider');
+ }
+
+ $this->lockProviderClass = $lockProviderClass;
+ }
+
+ private function getLockProvider(): ?ILockProvider {
+ if ($this->lockProvider) {
+ return $this->lockProvider;
+ }
+ if ($this->lockProviderClass) {
+ try {
+ $this->lockProvider = \OCP\Server::get($this->lockProviderClass);
+ } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
+ }
+ }
+
+ return $this->lockProvider;
+ }
+
public function isLockProviderAvailable(): bool {
- return $this->lockProvider !== null;
+ return $this->getLockProvider() !== null;
}
public function runInScope(LockContext $lock, callable $callback): void {
- if (!$this->lockProvider) {
+ if (!$this->getLockProvider()) {
$callback();
return;
}
@@ -47,26 +72,26 @@ class LockManager implements ILockManager {
}
public function getLocks(int $fileId): array {
- if (!$this->lockProvider) {
+ if (!$this->getLockProvider()) {
throw new PreConditionNotMetException('No lock provider available');
}
- return $this->lockProvider->getLocks($fileId);
+ return $this->getLockProvider()->getLocks($fileId);
}
public function lock(LockContext $lockInfo): ILock {
- if (!$this->lockProvider) {
+ if (!$this->getLockProvider()) {
throw new PreConditionNotMetException('No lock provider available');
}
- return $this->lockProvider->lock($lockInfo);
+ return $this->getLockProvider()->lock($lockInfo);
}
public function unlock(LockContext $lockInfo): void {
- if (!$this->lockProvider) {
+ if (!$this->getLockProvider()) {
throw new PreConditionNotMetException('No lock provider available');
}
- $this->lockProvider->unlock($lockInfo);
+ $this->getLockProvider()->unlock($lockInfo);
}
}
diff --git a/lib/public/Files/Lock/ILockManager.php b/lib/public/Files/Lock/ILockManager.php
index 2cdb027a570..d29743b7566 100644
--- a/lib/public/Files/Lock/ILockManager.php
+++ b/lib/public/Files/Lock/ILockManager.php
@@ -42,10 +42,18 @@ interface ILockManager extends ILockProvider {
/**
* @throws PreConditionNotMetException if there is already a lock provider registered
* @since 24.0.0
+ * @deprecated 30.0.0 Use registerLazyLockProvider
*/
public function registerLockProvider(ILockProvider $lockProvider): void;
/**
+ * @param string $lockProviderClass
+ * @return void
+ * @since 30.0.0
+ */
+ public function registerLazyLockProvider(string $lockProviderClass): void;
+
+ /**
* @return bool
* @since 24.0.0
*/