1
0

LockedException.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCP\Lock;
  28. /**
  29. * Class LockedException
  30. *
  31. * @since 8.1.0
  32. */
  33. class LockedException extends \Exception {
  34. /**
  35. * Locked path
  36. *
  37. * @var string
  38. */
  39. private $path;
  40. /** @var string|null */
  41. private $existingLock;
  42. /**
  43. * LockedException constructor.
  44. *
  45. * @param string $path locked path
  46. * @param \Exception|null $previous previous exception for cascading
  47. * @param string $existingLock since 14.0.0
  48. * @param string $readablePath since 20.0.0
  49. * @since 8.1.0
  50. */
  51. public function __construct(string $path, \Exception $previous = null, string $existingLock = null, string $readablePath = null) {
  52. if ($readablePath) {
  53. $message = "\"$path\"(\"$readablePath\") is locked";
  54. } else {
  55. $message = '"' . $path . '" is locked';
  56. }
  57. $this->existingLock = $existingLock;
  58. if ($existingLock) {
  59. $message .= ', existing lock on file: ' . $existingLock;
  60. }
  61. parent::__construct($message, 0, $previous);
  62. $this->path = $path;
  63. }
  64. /**
  65. * @return string
  66. * @since 8.1.0
  67. */
  68. public function getPath(): string {
  69. return $this->path;
  70. }
  71. /**
  72. * @return string
  73. * @since 19.0.0
  74. */
  75. public function getExistingLock(): ?string {
  76. return $this->existingLock;
  77. }
  78. }