diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 56d683ffa2575..eb04a0077a4f8 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -772,9 +772,7 @@ public function changeLock($path, $type, ILockingProvider $provider) { try { $provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); } catch (LockedException $e) { - if ($logger) { - $logger->logException($e); - } + \OC::$server->getLogger()->logException($e); throw $e; } } diff --git a/lib/private/Lock/MemcacheLockingProvider.php b/lib/private/Lock/MemcacheLockingProvider.php index c4b1469b50f82..ddd73aec0954d 100644 --- a/lib/private/Lock/MemcacheLockingProvider.php +++ b/lib/private/Lock/MemcacheLockingProvider.php @@ -71,12 +71,12 @@ public function isLocked($path, $type) { public function acquireLock($path, $type) { if ($type === self::LOCK_SHARED) { if (!$this->memcache->inc($path)) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } else { $this->memcache->add($path, 0); if (!$this->memcache->cas($path, 0, 'exclusive')) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } $this->setTTL($path); @@ -114,15 +114,26 @@ public function releaseLock($path, $type) { public function changeLock($path, $targetType) { if ($targetType === self::LOCK_SHARED) { if (!$this->memcache->cas($path, 'exclusive', 1)) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } else if ($targetType === self::LOCK_EXCLUSIVE) { // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock if (!$this->memcache->cas($path, 1, 'exclusive')) { - throw new LockedException($path); + throw new LockedException($path, null, $this->getExistingLockForException($path)); } } $this->setTTL($path); $this->markChange($path, $targetType); } + + private function getExistingLockForException($path) { + $existing = $this->memcache->get($path); + if (!$existing) { + return 'none'; + } else if ($existing === 'exclusive') { + return $existing; + } else { + return $existing . ' shared locks'; + } + } } diff --git a/lib/public/Lock/LockedException.php b/lib/public/Lock/LockedException.php index 5b5d88c18cacc..26ded4c8952ba 100644 --- a/lib/public/Lock/LockedException.php +++ b/lib/public/Lock/LockedException.php @@ -45,11 +45,15 @@ class LockedException extends \Exception { * * @param string $path locked path * @param \Exception|null $previous previous exception for cascading - * + * @param string $existingLock since 13.0.3 * @since 8.1.0 */ - public function __construct($path, \Exception $previous = null) { - parent::__construct('"' . $path . '" is locked', 0, $previous); + public function __construct($path, \Exception $previous = null, $existingLock = null) { + $message = '"' . $path . '" is locked'; + if ($existingLock) { + $message .= ', existing lock on file: ' . $existingLock; + } + parent::__construct($message, 0, $previous); $this->path = $path; }