Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,7 @@ public function changeLock($path, $type, ILockingProvider $provider) {
try {
$provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type);
} catch (LockedException $e) {
if ($logger) {
$logger->logException($e);
}
\OC::$server->getLogger()->logException($e);
throw $e;
}
}
Expand Down
19 changes: 15 additions & 4 deletions lib/private/Lock/MemcacheLockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public function isLocked($path, $type) {
public function acquireLock($path, $type) {
if ($type === self::LOCK_SHARED) {
if (!$this->memcache->inc($path)) {
throw new LockedException($path);
throw new LockedException($path, null, $this->getExistingLockForException($path));
}
} else {
$this->memcache->add($path, 0);
if (!$this->memcache->cas($path, 0, 'exclusive')) {
throw new LockedException($path);
throw new LockedException($path, null, $this->getExistingLockForException($path));
}
}
$this->setTTL($path);
Expand Down Expand Up @@ -114,15 +114,26 @@ public function releaseLock($path, $type) {
public function changeLock($path, $targetType) {
if ($targetType === self::LOCK_SHARED) {
if (!$this->memcache->cas($path, 'exclusive', 1)) {
throw new LockedException($path);
throw new LockedException($path, null, $this->getExistingLockForException($path));
}
} else if ($targetType === self::LOCK_EXCLUSIVE) {
// we can only change a shared lock to an exclusive if there's only a single owner of the shared lock
if (!$this->memcache->cas($path, 1, 'exclusive')) {
throw new LockedException($path);
throw new LockedException($path, null, $this->getExistingLockForException($path));
}
}
$this->setTTL($path);
$this->markChange($path, $targetType);
}

private function getExistingLockForException($path) {
$existing = $this->memcache->get($path);
if (!$existing) {
return 'none';
} else if ($existing === 'exclusive') {
return $existing;
} else {
return $existing . ' shared locks';
}
}
}
10 changes: 7 additions & 3 deletions lib/public/Lock/LockedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ class LockedException extends \Exception {
*
* @param string $path locked path
* @param \Exception|null $previous previous exception for cascading
*
* @param string $existingLock since 13.0.3
* @since 8.1.0
*/
public function __construct($path, \Exception $previous = null) {
parent::__construct('"' . $path . '" is locked', 0, $previous);
public function __construct($path, \Exception $previous = null, $existingLock = null) {
$message = '"' . $path . '" is locked';
if ($existingLock) {
$message .= ', existing lock on file: ' . $existingLock;
}
parent::__construct($message, 0, $previous);
$this->path = $path;
}

Expand Down