summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2020-10-27 22:57:24 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2020-11-07 10:31:26 -0500
commita66fb45c0b19c9f6fce55f06919562e99ceb1d6f (patch)
treefcbc9360ab980c4b313b3723eb0f4011754466e9 /lib
parentcad2369e0b0d9619b1c715e2912f68de07e7de1e (diff)
downloadnextcloud-server-a66fb45c0b19c9f6fce55f06919562e99ceb1d6f.tar.gz
nextcloud-server-a66fb45c0b19c9f6fce55f06919562e99ceb1d6f.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>
Diffstat (limited to 'lib')
-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 16074a89ca8..fba412c37d4 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 */
[$storage, $internalPath] = $this->resolvePath($path);