Skip to content
Snippets Groups Projects
Unverified Commit e900f424 authored by Morris Jobke's avatar Morris Jobke Committed by GitHub
Browse files

Merge pull request #21636 from nextcloud/lock-exception-readable-path

add proper paths to locking exceptions
parents d3d11cb8 da2d4250
No related branches found
No related tags found
No related merge requests found
......@@ -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]);
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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
}
......
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment