Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore NoUserException for shares from ghosts #3953

Merged
merged 4 commits into from
Mar 23, 2017
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
20 changes: 18 additions & 2 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@

namespace OCA\Files_Sharing;

use OC\Files\Filesystem;
use OC\Files\Cache\FailedCache;
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OCA\Files_Sharing\ISharedStorage;
use OC\Files\Storage\FailedStorage;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
use OCP\Lock\ILockingProvider;
use OC\User\NoUserException;

/**
* Convert target path to source path and pass the function call to the correct storage provider
Expand Down Expand Up @@ -99,6 +99,7 @@ public function __construct($arguments) {
private function getSourceRootInfo() {
if (is_null($this->sourceRootInfo)) {
if (is_null($this->superShare->getNodeCacheEntry())) {
$this->init();
$this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath);
} else {
$this->sourceRootInfo = $this->superShare->getNodeCacheEntry();
Expand All @@ -121,13 +122,25 @@ private function init() {
'mask' => $this->superShare->getPermissions()
]);
} catch (NotFoundException $e) {
// original file not accessible or deleted, set FailedStorage
$this->storage = new FailedStorage(['exception' => $e]);
$this->cache = new FailedCache();
$this->rootPath = '';
} catch (NoUserException $e) {
// sharer user deleted, set FailedStorage
$this->storage = new FailedStorage(['exception' => $e]);
$this->cache = new FailedCache();
$this->rootPath = '';
} catch (\Exception $e) {
$this->storage = new FailedStorage(['exception' => $e]);
$this->cache = new FailedCache();
$this->rootPath = '';
$this->logger->logException($e);
}

if (!$this->nonMaskedStorage) {
$this->nonMaskedStorage = $this->storage;
}
}

/**
Expand Down Expand Up @@ -344,6 +357,9 @@ public function getCache($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}
if ($this->storage instanceof FailedStorage) {
return new FailedCache();
}
$this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare);
return $this->cache;
}
Expand Down
38 changes: 38 additions & 0 deletions apps/files_sharing/tests/SharedStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

namespace OCA\Files_Sharing\Tests;

use OCA\Files_Sharing\SharedStorage;
use OCP\Share\IShare;
use OC\Files\View;
use OCP\Files\NotFoundException;

/**
* Class SharedStorageTest
*
Expand Down Expand Up @@ -559,4 +564,37 @@ public function testOwnerPermissions() {
$this->shareManager->deleteShare($share);

}

public function testInitWithNonExistingUser() {
$share = $this->createMock(IShare::class);
$share->method('getShareOwner')->willReturn('unexist');
$ownerView = $this->createMock(View::class);
$storage = new SharedStorage([
'ownerView' => $ownerView,
'superShare' => $share,
'groupedShares' => [$share],
'user' => 'user1',
]);

// trigger init
$this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
$this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
}

public function testInitWithNotFoundSource() {
$share = $this->createMock(IShare::class);
$share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
$ownerView = $this->createMock(View::class);
$ownerView->method('getPath')->will($this->throwException(new NotFoundException()));
$storage = new SharedStorage([
'ownerView' => $ownerView,
'superShare' => $share,
'groupedShares' => [$share],
'user' => 'user1',
]);

// trigger init
$this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
$this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
}
}