while some code paths do wrap the "raw" locking exception into one with a proper path, not all of them do
by adding the proper path to the original exception we ensure that we always have the usefull information in out logs
Signed-off-by: Robin Appelman <robin@icewind.nl>
);
}
try {
- $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
+ $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type, $this->getId() . '::' . $path);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e, ['level' => ILogger::INFO]);
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
* @throws \OCP\Lock\LockedException
*/
- public function acquireLock(string $path, int $type) {
+ public function acquireLock(string $path, int $type, string $readablePath = null) {
$expire = $this->getExpireTime();
if ($type === self::LOCK_SHARED) {
if (!$this->isLocallyLocked($path)) {
}
}
if ($result !== 1) {
- throw new LockedException($path);
+ throw new LockedException($path, null, null, $readablePath);
}
$this->markAcquire($path, $type);
}
/**
* @param string $path
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
+ * @param string $readablePath human readable path to use in error messages
* @throws \OCP\Lock\LockedException
*/
- public function acquireLock(string $path, int $type) {
+ public function acquireLock(string $path, int $type, string $readablePath = null) {
if ($type === self::LOCK_SHARED) {
if (!$this->memcache->inc($path)) {
- throw new LockedException($path, null, $this->getExistingLockForException($path));
+ throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath);
}
} else {
$this->memcache->add($path, 0);
if (!$this->memcache->cas($path, 0, 'exclusive')) {
- throw new LockedException($path, null, $this->getExistingLockForException($path));
+ throw new LockedException($path, null, $this->getExistingLockForException($path), $readablePath);
}
}
$this->setTTL($path);
/**
* {@inheritdoc}
*/
- public function acquireLock(string $path, int $type) {
+ public function acquireLock(string $path, int $type, string $readablePath = null) {
// do nothing
}
/**
* @param string $path
* @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
+ * @param string $readablePath human readable path to use in error messages, since 20.0.0
* @throws \OCP\Lock\LockedException
* @since 8.1.0
*/
- public function acquireLock(string $path, int $type);
+ public function acquireLock(string $path, int $type, string $readablePath = null);
/**
* @param string $path
* @param string $path locked path
* @param \Exception|null $previous previous exception for cascading
* @param string $existingLock since 14.0.0
+ * @param string $readablePath since 20.0.0
* @since 8.1.0
*/
- public function __construct(string $path, \Exception $previous = null, string $existingLock = null) {
- $message = '"' . $path . '" is locked';
+ public function __construct(string $path, \Exception $previous = null, string $existingLock = null, string $readablePath = null) {
+ if ($readablePath) {
+ $message = "\"$path\"(\"$readablePath\") is locked";
+ } else {
+ $message = '"' . $path . '" is locked';
+ }
$this->existingLock = $existingLock;
if ($existingLock) {
$message .= ', existing lock on file: ' . $existingLock;