You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1 KiB

3 years ago
  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 <pvince81@owncloud.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. }