Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-06-30 19:10:42 +0300
committerRobin Appelman <robin@icewind.nl>2020-07-02 14:59:26 +0300
commit413f92aa5140e69ede4cbac0adc62745b821d941 (patch)
treef57f00464d2c6aed91b1c5ad488f3790f8c80b13
parent2d2b41300a4817412735932efe9292fd59dda764 (diff)
add proper paths to locking exceptionslock-exception-readable-path-18
while some code paths do wrap the "raw" locking exception into one with a proper path, not all of them do by adding the proper path to the original exception we ensure that we always have the usefull information in out logs Signed-off-by: Robin Appelman <robin@icewind.nl>
-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 82ac49b9fdf..e28c941f042 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -744,7 +744,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 974b0b55c89..df466331a00 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 6cab64b3a02..46fe07e43c1 100644
--- a/lib/private/Lock/MemcacheLockingProvider.php
+++ b/lib/private/Lock/MemcacheLockingProvider.php
@@ -70,17 +70,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 4403b091993..60e4854c543 100644
--- a/lib/public/Lock/ILockingProvider.php
+++ b/lib/public/Lock/ILockingProvider.php
@@ -54,10 +54,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 99205b54d24..72c15907d8b 100644
--- a/lib/public/Lock/LockedException.php
+++ b/lib/public/Lock/LockedException.php
@@ -50,10 +50,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';
+ }
if ($existingLock) {
$message .= ', existing lock on file: ' . $existingLock;
}