Skip to content
Merged
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
Unlock when promoting to exclusive lock fails
In certain cases changeLock to EXCLUSIVE fails
and throws LockedException. This leaves the
file locked as SHARED in file_put_contents,
which prevents retrying (because on second
call file_put_contents takes another SHARED
lock on the same file, and changeLock doesn't
allow more than a single SHARED lock to promote
to EXCLUSIVE).

To avoid this case, we catch the LockedException
and unlock before re-throwing.

Signed-off-by: Ashod Nakashian <[email protected]>
  • Loading branch information
Ashod authored and backportbot[bot] committed Nov 12, 2020
commit a428cfeb2627769c8b9aed70eb6cac18080d17e5
8 changes: 7 additions & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,13 @@ public function file_put_contents($path, $data) {
return false;
}

$this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
try {
$this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
} catch (\Exception $e) {
// Release the shared lock before throwing.
$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
throw $e;
}

/** @var \OC\Files\Storage\Storage $storage */
list($storage, $internalPath) = $this->resolvePath($path);
Expand Down