|
|
|
|
@ -61,7 +61,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param string $path |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
protected function isLocallyLocked($path) { |
|
|
|
|
protected function isLocallyLocked(string $path): bool { |
|
|
|
|
return isset($this->sharedLocks[$path]) && $this->sharedLocks[$path]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -71,7 +71,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param string $path |
|
|
|
|
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
|
|
|
*/ |
|
|
|
|
protected function markAcquire($path, $type) { |
|
|
|
|
protected function markAcquire(string $path, int $type) { |
|
|
|
|
parent::markAcquire($path, $type); |
|
|
|
|
if ($type === self::LOCK_SHARED) { |
|
|
|
|
$this->sharedLocks[$path] = true; |
|
|
|
|
@ -84,7 +84,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param string $path |
|
|
|
|
* @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
|
|
|
*/ |
|
|
|
|
protected function markChange($path, $targetType) { |
|
|
|
|
protected function markChange(string $path, int $targetType) { |
|
|
|
|
parent::markChange($path, $targetType); |
|
|
|
|
if ($targetType === self::LOCK_SHARED) { |
|
|
|
|
$this->sharedLocks[$path] = true; |
|
|
|
|
@ -99,7 +99,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory |
|
|
|
|
* @param int $ttl |
|
|
|
|
*/ |
|
|
|
|
public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory, $ttl = 3600) { |
|
|
|
|
public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory, int $ttl = 3600) { |
|
|
|
|
$this->connection = $connection; |
|
|
|
|
$this->logger = $logger; |
|
|
|
|
$this->timeFactory = $timeFactory; |
|
|
|
|
@ -114,7 +114,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @return int number of inserted rows |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
protected function initLockField($path, $lock = 0) { |
|
|
|
|
protected function initLockField(string $path, int $lock = 0): int { |
|
|
|
|
$expire = $this->getExpireTime(); |
|
|
|
|
return $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire], ['key']); |
|
|
|
|
} |
|
|
|
|
@ -122,7 +122,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
/** |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
protected function getExpireTime() { |
|
|
|
|
protected function getExpireTime(): int { |
|
|
|
|
return $this->timeFactory->getTime() + $this->ttl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -131,7 +131,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
public function isLocked($path, $type) { |
|
|
|
|
public function isLocked(string $path, int $type): bool { |
|
|
|
|
if ($this->hasAcquiredLock($path, $type)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -157,7 +157,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
|
|
|
* @throws \OCP\Lock\LockedException |
|
|
|
|
*/ |
|
|
|
|
public function acquireLock($path, $type) { |
|
|
|
|
public function acquireLock(string $path, int $type) { |
|
|
|
|
$expire = $this->getExpireTime(); |
|
|
|
|
if ($type === self::LOCK_SHARED) { |
|
|
|
|
if (!$this->isLocallyLocked($path)) { |
|
|
|
|
@ -194,7 +194,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param string $path |
|
|
|
|
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
|
|
|
*/ |
|
|
|
|
public function releaseLock($path, $type) { |
|
|
|
|
public function releaseLock(string $path, int $type) { |
|
|
|
|
$this->markRelease($path, $type); |
|
|
|
|
|
|
|
|
|
// we keep shared locks till the end of the request so we can re-use them |
|
|
|
|
@ -213,7 +213,7 @@ class DBLockingProvider extends AbstractLockingProvider { |
|
|
|
|
* @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
|
|
|
* @throws \OCP\Lock\LockedException |
|
|
|
|
*/ |
|
|
|
|
public function changeLock($path, $targetType) { |
|
|
|
|
public function changeLock(string $path, int $targetType) { |
|
|
|
|
$expire = $this->getExpireTime(); |
|
|
|
|
if ($targetType === self::LOCK_SHARED) { |
|
|
|
|
$result = $this->connection->executeUpdate( |
|
|
|
|
|