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
re-acquired expired shared locks on large file uploads
during large file uploads, the shared lock that we get at the begining can expire
leading to locked errors later on, instead of erroring, try to re-get the lock

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and Backportbot committed Nov 14, 2019
commit 61382f525b0fd75e2687e25d8fb193f7cc0b1b90
18 changes: 15 additions & 3 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,22 @@ public function put($data) {
try {
$this->changeLock(ILockingProvider::LOCK_EXCLUSIVE);
} catch (LockedException $e) {
if ($needsPartFile) {
$partStorage->unlink($internalPartPath);
// during very large uploads, the shared lock we got at the start might have been expired
// meaning that the above lock can fail not just only because somebody else got a shared lock
// or because there is no existing shared lock to make exclusive
//
// Thus we try to get a new exclusive lock, if the original lock failed because of a different shared
// lock this will still fail, if our original shared lock expired the new lock will be successful and
// the entire operation will be safe

try {
$this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE);
} catch (LockedException $e) {
if ($needsPartFile) {
$partStorage->unlink($internalPartPath);
}
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}

// rename to correct path
Expand Down
21 changes: 21 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,4 +1201,25 @@ public function testSimplePutNoCreatePermissions() {

$this->assertEquals('new content', $view->file_get_contents('root/file.txt'));
}

public function testPutLockExpired() {
$view = new \OC\Files\View('/' . $this->user . '/files/');

$path = 'test-locking.txt';
$info = new \OC\Files\FileInfo(
'/' . $this->user . '/files/' . $path,
$this->getMockStorage(),
null,
['permissions' => \OCP\Constants::PERMISSION_ALL],
null
);

$file = new \OCA\DAV\Connector\Sabre\File($view, $info);

// don't lock before the PUT to simulate an expired shared lock
$this->assertNotEmpty($file->put($this->getStream('test data')));

// afterMethod unlocks
$view->unlockFile($path, ILockingProvider::LOCK_SHARED);
}
}