2015-04-29 15:19:02 +00:00
|
|
|
<?php
|
2019-12-03 18:57:53 +00:00
|
|
|
|
2018-01-16 18:34:43 +00:00
|
|
|
declare(strict_types=1);
|
2015-04-29 15:19:02 +00:00
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-04-29 15:19:02 +00:00
|
|
|
*/
|
|
|
|
namespace OCP\Lock;
|
|
|
|
|
2015-06-05 15:30:45 +00:00
|
|
|
/**
|
|
|
|
* Class LockedException
|
|
|
|
*
|
|
|
|
* @since 8.1.0
|
|
|
|
*/
|
2015-04-29 15:19:02 +00:00
|
|
|
class LockedException extends \Exception {
|
2015-04-30 12:16:09 +00:00
|
|
|
/**
|
2015-06-11 16:32:15 +00:00
|
|
|
* Locked path
|
|
|
|
*
|
2015-04-30 12:16:09 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $path;
|
|
|
|
|
2020-03-02 16:47:48 +00:00
|
|
|
/** @var string|null */
|
|
|
|
private $existingLock;
|
|
|
|
|
2015-04-30 12:16:09 +00:00
|
|
|
/**
|
|
|
|
* LockedException constructor.
|
|
|
|
*
|
2015-06-11 16:32:15 +00:00
|
|
|
* @param string $path locked path
|
2017-07-19 17:44:10 +00:00
|
|
|
* @param \Exception|null $previous previous exception for cascading
|
2018-05-04 11:30:18 +00:00
|
|
|
* @param string $existingLock since 14.0.0
|
2020-06-30 16:10:42 +00:00
|
|
|
* @param string $readablePath since 20.0.0
|
2015-06-05 15:30:45 +00:00
|
|
|
* @since 8.1.0
|
2015-04-30 12:16:09 +00:00
|
|
|
*/
|
2024-03-28 15:13:19 +00:00
|
|
|
public function __construct(string $path, ?\Exception $previous = null, ?string $existingLock = null, ?string $readablePath = null) {
|
2020-06-30 16:10:42 +00:00
|
|
|
if ($readablePath) {
|
|
|
|
$message = "\"$path\"(\"$readablePath\") is locked";
|
|
|
|
} else {
|
|
|
|
$message = '"' . $path . '" is locked';
|
|
|
|
}
|
2020-03-02 16:47:48 +00:00
|
|
|
$this->existingLock = $existingLock;
|
2018-05-04 11:30:18 +00:00
|
|
|
if ($existingLock) {
|
|
|
|
$message .= ', existing lock on file: ' . $existingLock;
|
|
|
|
}
|
|
|
|
parent::__construct($message, 0, $previous);
|
2015-04-30 12:16:09 +00:00
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
2015-06-05 15:30:45 +00:00
|
|
|
* @since 8.1.0
|
2015-04-30 12:16:09 +00:00
|
|
|
*/
|
2018-01-16 18:34:43 +00:00
|
|
|
public function getPath(): string {
|
2015-04-30 12:16:09 +00:00
|
|
|
return $this->path;
|
|
|
|
}
|
2020-03-02 16:47:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @since 19.0.0
|
|
|
|
*/
|
|
|
|
public function getExistingLock(): ?string {
|
|
|
|
return $this->existingLock;
|
|
|
|
}
|
2015-04-29 15:19:02 +00:00
|
|
|
}
|