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
8 changes: 7 additions & 1 deletion apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ public function childExists($name) {
// TODO: resolve chunk file name here and implement "updateFile"
$path = $this->path . '/' . $name;
$path = FileSystem::normalizePath($path);
return $this->fileView->file_exists($path);
try {
return $this->fileView->file_exists($path);
} catch (StorageNotAvailableException $e) {
throw new SabreServiceUnavailable($e->getMessage());
}
}

/**
Expand All @@ -344,6 +348,8 @@ public function delete() {
throw new Forbidden($ex->getMessage(), $ex->getRetry());
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
} catch (StorageNotAvailableException $e) {
throw new SabreServiceUnavailable($e->getMessage());
}
}

Expand Down
49 changes: 48 additions & 1 deletion apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\Files\FileContentNotAllowedException;
use OCP\Files\ForbiddenException;
use OCP\Constants;
use OCP\Files\StorageNotAvailableException;

class TestDoubleFileView extends \OC\Files\View {
private $updatables;
Expand Down Expand Up @@ -96,6 +97,33 @@ private function getDir($path = '/') {
return new Directory($this->view, $this->info);
}

public function childExistsProvider() {
return [
[true],
[false],
];
}

/**
* @dataProvider childExistsProvider
*/
public function testChildExists($exists) {
$this->view->method('file_exists')
->willReturn($exists);
$dir = $this->getDir();
$this->assertSame($exists, $dir->childExists('/foo'));
}

/**
* @expectedException \Sabre\DAV\Exception\ServiceUnavailable
*/
public function testChildExistsStorageNotAvailable() {
$this->view->method('file_exists')
->will($this->throwException(new StorageNotAvailableException()));
$dir = $this->getDir();
$dir->childExists('/foo');
}

/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
Expand Down Expand Up @@ -178,6 +206,25 @@ public function testDeleteFolderThrowsWhenDeletionFailed() {
$dir->delete();
}

/**
* @expectedException \Sabre\DAV\Exception\ServiceUnavailable
*/
public function testDeleteFolderThrowsWhenStorageNotAvailable() {
// deletion allowed
$this->info->expects($this->once())
->method('isDeletable')
->will($this->returnValue(true));

// but fails
$this->view->expects($this->once())
->method('rmdir')
->with('sub')
->will($this->throwException(new StorageNotAvailableException()));

$dir = $this->getDir('sub');
$dir->delete();
}

public function testGetChildren() {
$info1 = $this->getMockBuilder('OC\Files\FileInfo')
->disableOriginalConstructor()
Expand Down Expand Up @@ -253,7 +300,7 @@ public function testGetChildNoPermission() {
public function testGetChildThrowStorageNotAvailableException() {
$this->view->expects($this->once())
->method('getFileInfo')
->willThrowException(new \OCP\Files\StorageNotAvailableException());
->willThrowException(new StorageNotAvailableException());

$dir = new Directory($this->view, $this->info);
$dir->getChild('.');
Expand Down
12 changes: 0 additions & 12 deletions lib/private/Files/External/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,6 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$impl = new FailedStorage(['exception' => $e]);
}

try {
$availability = $impl->getAvailability();
if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
$impl = new FailedStorage([
'exception' => new StorageNotAvailableException('Storage with mount id ' . $storage->getId() . ' is not available')
]);
}
} catch (\Exception $e) {
// propagate exception into filesystem
$impl = new FailedStorage(['exception' => $e]);
}

$mount = new MountPoint(
$impl,
'/' . $user->getUID() . '/files' . $storage->getMountPoint(),
Expand Down