summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2020-10-27 22:57:24 -0400
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2020-11-12 19:07:35 +0000
commitda7f445179ba682cea57be621caf0da3b7d637bc (patch)
treebc39136eb6979be8e89984ab04e0a5b90ed212fe
parent9c59778ee15e3bb23458535128192bea82214566 (diff)
downloadnextcloud-server-da7f445179ba682cea57be621caf0da3b7d637bc.tar.gz
nextcloud-server-da7f445179ba682cea57be621caf0da3b7d637bc.zip
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 <ashod.nakashian@collabora.co.uk>
-rw-r--r--lib/private/Files/View.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index ef8656258d1..0c0bef6600a 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -665,7 +665,13 @@ class View {
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);