Merge pull request #3953 from nextcloud/downstream-27027
Ignore NoUserException for shares from ghosts
This commit is contained in:
commit
a5a29ee27a
|
@ -31,16 +31,16 @@
|
||||||
|
|
||||||
namespace OCA\Files_Sharing;
|
namespace OCA\Files_Sharing;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
|
||||||
use OC\Files\Cache\FailedCache;
|
use OC\Files\Cache\FailedCache;
|
||||||
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\Storage\Wrapper\PermissionsMask;
|
use OC\Files\Storage\Wrapper\PermissionsMask;
|
||||||
use OCA\Files_Sharing\ISharedStorage;
|
|
||||||
use OC\Files\Storage\FailedStorage;
|
use OC\Files\Storage\FailedStorage;
|
||||||
use OCP\Constants;
|
use OCP\Constants;
|
||||||
use OCP\Files\Cache\ICacheEntry;
|
use OCP\Files\Cache\ICacheEntry;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\Files\Storage\IStorage;
|
use OCP\Files\Storage\IStorage;
|
||||||
use OCP\Lock\ILockingProvider;
|
use OCP\Lock\ILockingProvider;
|
||||||
|
use OC\User\NoUserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert target path to source path and pass the function call to the correct storage provider
|
* Convert target path to source path and pass the function call to the correct storage provider
|
||||||
|
@ -99,6 +99,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
|
||||||
private function getSourceRootInfo() {
|
private function getSourceRootInfo() {
|
||||||
if (is_null($this->sourceRootInfo)) {
|
if (is_null($this->sourceRootInfo)) {
|
||||||
if (is_null($this->superShare->getNodeCacheEntry())) {
|
if (is_null($this->superShare->getNodeCacheEntry())) {
|
||||||
|
$this->init();
|
||||||
$this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath);
|
$this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath);
|
||||||
} else {
|
} else {
|
||||||
$this->sourceRootInfo = $this->superShare->getNodeCacheEntry();
|
$this->sourceRootInfo = $this->superShare->getNodeCacheEntry();
|
||||||
|
@ -121,13 +122,25 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
|
||||||
'mask' => $this->superShare->getPermissions()
|
'mask' => $this->superShare->getPermissions()
|
||||||
]);
|
]);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
|
// original file not accessible or deleted, set FailedStorage
|
||||||
$this->storage = new FailedStorage(['exception' => $e]);
|
$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 = '';
|
$this->rootPath = '';
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->storage = new FailedStorage(['exception' => $e]);
|
$this->storage = new FailedStorage(['exception' => $e]);
|
||||||
|
$this->cache = new FailedCache();
|
||||||
$this->rootPath = '';
|
$this->rootPath = '';
|
||||||
$this->logger->logException($e);
|
$this->logger->logException($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->nonMaskedStorage) {
|
||||||
|
$this->nonMaskedStorage = $this->storage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -344,6 +357,9 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
|
||||||
if (!$storage) {
|
if (!$storage) {
|
||||||
$storage = $this;
|
$storage = $this;
|
||||||
}
|
}
|
||||||
|
if ($this->storage instanceof FailedStorage) {
|
||||||
|
return new FailedCache();
|
||||||
|
}
|
||||||
$this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare);
|
$this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare);
|
||||||
return $this->cache;
|
return $this->cache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,11 @@
|
||||||
|
|
||||||
namespace OCA\Files_Sharing\Tests;
|
namespace OCA\Files_Sharing\Tests;
|
||||||
|
|
||||||
|
use OCA\Files_Sharing\SharedStorage;
|
||||||
|
use OCP\Share\IShare;
|
||||||
|
use OC\Files\View;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SharedStorageTest
|
* Class SharedStorageTest
|
||||||
*
|
*
|
||||||
|
@ -559,4 +564,37 @@ class SharedStorageTest extends TestCase {
|
||||||
$this->shareManager->deleteShare($share);
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue