Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2019-01-22 17:32:48 +0300
committerBackportbot <backportbot-noreply@rullzer.com>2019-01-22 18:13:40 +0300
commit0625d2957c3db5a458938b497577bc0dba56bdb1 (patch)
treef773844a86e977cf8081561ad58b40677827c8d3
parent417997220f75fddece145a2bc2e70e84e4e69372 (diff)
cleanup shared lock if changing to exclusive lock failed
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/View.php8
-rw-r--r--tests/lib/Files/ViewTest.php31
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 21df67cf557..6066aed411f 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1137,7 +1137,13 @@ class View {
list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
if ($run and $storage) {
if (in_array('write', $hooks) || in_array('delete', $hooks)) {
- $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
+ try {
+ $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
+ } catch (LockedException $e) {
+ // release the shared lock we acquired before quiting
+ $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
+ throw $e;
+ }
}
try {
if (!is_null($extraParam)) {
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 9b435f2b935..7a0f8c274df 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -1997,6 +1997,37 @@ class ViewTest extends \Test\TestCase {
$this->assertNull($this->getFileLockType($view, $path), 'File got unlocked after exception');
}
+ public function testLockBasicOperationUnlocksAfterLockException() {
+ $view = new View('/' . $this->user . '/files/');
+
+ $storage = new Temporary([]);
+
+ Filesystem::mount($storage, array(), $this->user . '/');
+
+ $storage->mkdir('files');
+ $storage->mkdir('files/dir');
+ $storage->file_put_contents('files/test.txt', 'blah');
+ $storage->getScanner()->scan('files');
+
+ // get a shared lock
+ $handle = $view->fopen('test.txt', 'r');
+
+ $thrown = false;
+ try {
+ // try (and fail) to get a write lock
+ $view->unlink('test.txt');
+ } catch (\Exception $e) {
+ $thrown = true;
+ $this->assertInstanceOf(LockedException::class, $e);
+ }
+ $this->assertTrue($thrown, 'Exception was rethrown');
+
+ // clean shared lock
+ fclose($handle);
+
+ $this->assertNull($this->getFileLockType($view, 'test.txt'), 'File got unlocked');
+ }
+
/**
* Test locks for fopen with fclose at the end
*