From fab22ac14cb8116006b11cb2bcfe0337daaa2138 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 2 Mar 2020 17:47:48 +0100 Subject: [PATCH] pass the existing locks info when making locked exception with absolute paths Signed-off-by: Robin Appelman --- apps/dav/lib/Connector/Sabre/File.php | 2 +- lib/private/Files/View.php | 11 +++++++---- lib/public/Lock/LockedException.php | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index a1f5e2fe876f2..098961ce1309c 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -263,7 +263,7 @@ public function put($data) { try { $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); - } catch (LockedException $e) { + } catch (LockedException $ex) { if ($needsPartFile) { $partStorage->unlink($internalPartPath); } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 2c01c112ad4ee..90ac1e1988d36 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1946,7 +1946,8 @@ private function lockPath($path, $type, $lockMountPoint = false) { // rethrow with the a human-readable path throw new LockedException( $this->getPathRelativeToFiles($absolutePath), - $e + $e, + $e->getExistingLock() ); } } @@ -1988,12 +1989,14 @@ public function changeLock($path, $type, $lockMountPoint = false) { // rethrow with the a human-readable path throw new LockedException( $this->getPathRelativeToFiles($absolutePath), - $e + $e, + $e->getExistingLock() ); - } catch (\InvalidArgumentException $e) { + } catch (\InvalidArgumentException $ex) { throw new LockedException( $absolutePath, - $e + $ex, + $e->getExistingLock() ); } } diff --git a/lib/public/Lock/LockedException.php b/lib/public/Lock/LockedException.php index 99205b54d2414..582157010ccb5 100644 --- a/lib/public/Lock/LockedException.php +++ b/lib/public/Lock/LockedException.php @@ -44,6 +44,9 @@ class LockedException extends \Exception { */ private $path; + /** @var string|null */ + private $existingLock; + /** * LockedException constructor. * @@ -54,6 +57,7 @@ class LockedException extends \Exception { */ public function __construct(string $path, \Exception $previous = null, string $existingLock = null) { $message = '"' . $path . '" is locked'; + $this->existingLock = $existingLock; if ($existingLock) { $message .= ', existing lock on file: ' . $existingLock; } @@ -68,4 +72,12 @@ public function __construct(string $path, \Exception $previous = null, string $e public function getPath(): string { return $this->path; } + + /** + * @return string + * @since 19.0.0 + */ + public function getExistingLock(): ?string { + return $this->existingLock; + } }