Skip to content

Commit

Permalink
Merge pull request #19746 from nextcloud/locked-exception-forward-exi…
Browse files Browse the repository at this point in the history
…sting

pass the existing locks info when making locked exception with absolu…
  • Loading branch information
rullzer authored Mar 9, 2020
2 parents 1f7cb02 + fab22ac commit b6245be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
Expand Down Expand Up @@ -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()
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/public/Lock/LockedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class LockedException extends \Exception {
*/
private $path;

/** @var string|null */
private $existingLock;

/**
* LockedException constructor.
*
Expand All @@ -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;
}
Expand All @@ -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;
}
}

0 comments on commit b6245be

Please sign in to comment.