summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-07-05 22:37:12 +0200
committerGitHub <noreply@github.com>2020-07-05 22:37:12 +0200
commite900f424ce16c40b85adc89387ab3b369140f532 (patch)
treeb27acb63303ed1085fe6158aafbb685d92bcab63 /lib
parentd3d11cb826654d9c597443edb1d22d63521a2698 (diff)
parentda2d4250446b6e2f921bd3de0420738881792bd3 (diff)
downloadnextcloud-server-e900f424ce16c40b85adc89387ab3b369140f532.tar.gz
nextcloud-server-e900f424ce16c40b85adc89387ab3b369140f532.zip
Merge pull request #21636 from nextcloud/lock-exception-readable-path
add proper paths to locking exceptions
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Storage/Common.php2
-rw-r--r--lib/private/Lock/DBLockingProvider.php4
-rw-r--r--lib/private/Lock/MemcacheLockingProvider.php7
-rw-r--r--lib/private/Lock/NoopLockingProvider.php2
-rw-r--r--lib/public/Lock/ILockingProvider.php3
-rw-r--r--lib/public/Lock/LockedException.php9
6 files changed, 17 insertions, 10 deletions
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php
index 001b16cb3b4..6c57405619a 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -747,7 +747,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
);
}
try {
- $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
+ $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type, $this->getId() . '::' . $path);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e, ['level' => ILogger::INFO]);
diff --git a/lib/private/Lock/DBLockingProvider.php b/lib/private/Lock/DBLockingProvider.php
index c32d7b4877a..f48bf57028f 100644
--- a/lib/private/Lock/DBLockingProvider.php
+++ b/lib/private/Lock/DBLockingProvider.php
@@ -180,7 +180,7 @@ class DBLockingProvider extends AbstractLockingProvider {
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
* @throws \OCP\Lock\LockedException
*/
- public function acquireLock(string $path, int $type) {
+ public function acquireLock(string $path, int $type, string $readablePath = null) {
$expire = $this->getExpireTime();
if ($type === self::LOCK_SHARED) {
if (!$this->isLocallyLocked($path)) {
@@ -208,7 +208,7 @@ class DBLockingProvider extends AbstractLockingProvider {
}
}
if ($result !== 1) {
- throw new LockedException($path);
+ throw new LockedException($path, null, null, $readablePath);
}
$this->markAcquire($path, $type);
}
diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php
index 3d7510f43ff..c9dfcea3197 100644
--- a/lib/private/Lock/MemcacheLockingProvider.php
+++ b/lib/private/Lock/MemcacheLockingProvider.php
@@ -71,17 +71,18 @@ class MemcacheLockingProvider extends AbstractLockingProvider {
/**
* @param string $path
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
+ * @param string $readablePath human readable path to use in error messages
* @throws \OCP\Lock\LockedException
*/
- public function acquireLock(string $path, int $type) {
+ public function acquireLock(string $path, int $type, string $readablePath = null) {
if ($type === self::LOCK_SHARED) {
if (!$this->memcache->inc($path)) {
- throw new LockedException($path, null, $this->getExistingLockForException($path));
+ throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath);
}
} else {
$this->memcache->add($path, 0);
if (!$this->memcache->cas($path, 0, 'exclusive')) {
- throw new LockedException($path, null, $this->getExistingLockForException($path));
+ throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath);
}
}
$this->setTTL($path);
diff --git a/lib/private/Lock/NoopLockingProvider.php b/lib/private/Lock/NoopLockingProvider.php
index 94612e22f53..4f38d5159b9 100644
--- a/lib/private/Lock/NoopLockingProvider.php
+++ b/lib/private/Lock/NoopLockingProvider.php
@@ -46,7 +46,7 @@ class NoopLockingProvider implements ILockingProvider {
/**
* {@inheritdoc}
*/
- public function acquireLock(string $path, int $type) {
+ public function acquireLock(string $path, int $type, string $readablePath = null) {
// do nothing
}
diff --git a/lib/public/Lock/ILockingProvider.php b/lib/public/Lock/ILockingProvider.php
index 34f69abdc09..6886b176c40 100644
--- a/lib/public/Lock/ILockingProvider.php
+++ b/lib/public/Lock/ILockingProvider.php
@@ -55,10 +55,11 @@ interface ILockingProvider {
/**
* @param string $path
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
+ * @param string $readablePath human readable path to use in error messages, since 20.0.0
* @throws \OCP\Lock\LockedException
* @since 8.1.0
*/
- public function acquireLock(string $path, int $type);
+ public function acquireLock(string $path, int $type, string $readablePath = null);
/**
* @param string $path
diff --git a/lib/public/Lock/LockedException.php b/lib/public/Lock/LockedException.php
index 582157010cc..4bd59c81b34 100644
--- a/lib/public/Lock/LockedException.php
+++ b/lib/public/Lock/LockedException.php
@@ -53,10 +53,15 @@ class LockedException extends \Exception {
* @param string $path locked path
* @param \Exception|null $previous previous exception for cascading
* @param string $existingLock since 14.0.0
+ * @param string $readablePath since 20.0.0
* @since 8.1.0
*/
- public function __construct(string $path, \Exception $previous = null, string $existingLock = null) {
- $message = '"' . $path . '" is locked';
+ public function __construct(string $path, \Exception $previous = null, string $existingLock = null, string $readablePath = null) {
+ if ($readablePath) {
+ $message = "\"$path\"(\"$readablePath\") is locked";
+ } else {
+ $message = '"' . $path . '" is locked';
+ }
$this->existingLock = $existingLock;
if ($existingLock) {
$message .= ', existing lock on file: ' . $existingLock;