1
0

LockedException.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCP\Lock;
  9. /**
  10. * Class LockedException
  11. *
  12. * @since 8.1.0
  13. */
  14. class LockedException extends \Exception {
  15. /**
  16. * Locked path
  17. *
  18. * @var string
  19. */
  20. private $path;
  21. /** @var string|null */
  22. private $existingLock;
  23. /**
  24. * LockedException constructor.
  25. *
  26. * @param string $path locked path
  27. * @param \Exception|null $previous previous exception for cascading
  28. * @param string $existingLock since 14.0.0
  29. * @param string $readablePath since 20.0.0
  30. * @since 8.1.0
  31. */
  32. public function __construct(string $path, ?\Exception $previous = null, ?string $existingLock = null, ?string $readablePath = null) {
  33. if ($readablePath) {
  34. $message = "\"$path\"(\"$readablePath\") is locked";
  35. } else {
  36. $message = '"' . $path . '" is locked';
  37. }
  38. $this->existingLock = $existingLock;
  39. if ($existingLock) {
  40. $message .= ', existing lock on file: ' . $existingLock;
  41. }
  42. parent::__construct($message, 0, $previous);
  43. $this->path = $path;
  44. }
  45. /**
  46. * @return string
  47. * @since 8.1.0
  48. */
  49. public function getPath(): string {
  50. return $this->path;
  51. }
  52. /**
  53. * @return string
  54. * @since 19.0.0
  55. */
  56. public function getExistingLock(): ?string {
  57. return $this->existingLock;
  58. }
  59. }