dont break when there is an invalid share
This commit is contained in:
parent
5a6b2956d8
commit
f29440dbbc
|
@ -29,6 +29,17 @@ use OCP\Files\Cache\ICache;
|
||||||
* Storage placeholder to represent a missing precondition, storage unavailable
|
* Storage placeholder to represent a missing precondition, storage unavailable
|
||||||
*/
|
*/
|
||||||
class FailedCache implements ICache {
|
class FailedCache implements ICache {
|
||||||
|
private $visible;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FailedCache constructor.
|
||||||
|
*
|
||||||
|
* @param bool $visible
|
||||||
|
*/
|
||||||
|
public function __construct($visible = true) {
|
||||||
|
$this->visible = $visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getNumericStorageId() {
|
public function getNumericStorageId() {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -41,7 +52,7 @@ class FailedCache implements ICache {
|
||||||
'size' => 0,
|
'size' => 0,
|
||||||
'mimetype' => 'httpd/unix-directory',
|
'mimetype' => 'httpd/unix-directory',
|
||||||
'mimepart' => 'httpd',
|
'mimepart' => 'httpd',
|
||||||
'permissions' => Constants::PERMISSION_READ,
|
'permissions' => $this->visible ? Constants::PERMISSION_READ : 0,
|
||||||
'mtime' => time()
|
'mtime' => time()
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
namespace OC\Files\Storage;
|
namespace OC\Files\Storage;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
|
use OCA\Files_External\Lib\FailedCache;
|
||||||
use OCA\Files_Sharing\ISharedStorage;
|
use OCA\Files_Sharing\ISharedStorage;
|
||||||
use OCP\Constants;
|
use OCP\Constants;
|
||||||
use OCP\Files\Cache\ICacheEntry;
|
use OCP\Files\Cache\ICacheEntry;
|
||||||
|
@ -67,10 +68,16 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
*/
|
*/
|
||||||
private $sourceStorage;
|
private $sourceStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \OCP\ILogger
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
public function __construct($arguments) {
|
public function __construct($arguments) {
|
||||||
$this->share = $arguments['share'];
|
$this->share = $arguments['share'];
|
||||||
$this->ownerView = $arguments['ownerView'];
|
$this->ownerView = $arguments['ownerView'];
|
||||||
$this->user = $arguments['user'];
|
$this->user = $arguments['user'];
|
||||||
|
$this->logger = \OC::$server->getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init() {
|
private function init() {
|
||||||
|
@ -78,15 +85,19 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->initialized = true;
|
$this->initialized = true;
|
||||||
Filesystem::initMountPoints($this->share['uid_owner']);
|
try {
|
||||||
$sourcePath = $this->ownerView->getPath($this->share['file_source']);
|
Filesystem::initMountPoints($this->share['uid_owner']);
|
||||||
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
|
$sourcePath = $this->ownerView->getPath($this->share['file_source']);
|
||||||
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
|
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
|
||||||
|
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->logger->logException($e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isValid() {
|
private function isValid() {
|
||||||
$this->init();
|
$this->init();
|
||||||
return ($this->sourceRootInfo->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
|
return $this->sourceRootInfo && ($this->sourceRootInfo->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -568,6 +579,9 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
|
||||||
|
|
||||||
public function getCache($path = '', $storage = null) {
|
public function getCache($path = '', $storage = null) {
|
||||||
$this->init();
|
$this->init();
|
||||||
|
if (is_null($this->sourceStorage)) {
|
||||||
|
return new FailedCache(false);
|
||||||
|
}
|
||||||
if (!$storage) {
|
if (!$storage) {
|
||||||
$storage = $this;
|
$storage = $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue