From 3bd6fc797dd5635f3881f303f3b475af636373a7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 9 Mar 2016 16:44:57 +0100 Subject: [PATCH 1/2] dont break when there is an invalid share --- apps/files_external/lib/failedcache.php | 13 ++++++++++++- apps/files_sharing/lib/sharedstorage.php | 24 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/apps/files_external/lib/failedcache.php b/apps/files_external/lib/failedcache.php index 0f59495e59..2fddb3eca8 100644 --- a/apps/files_external/lib/failedcache.php +++ b/apps/files_external/lib/failedcache.php @@ -29,6 +29,17 @@ use OCP\Files\Cache\ICache; * Storage placeholder to represent a missing precondition, storage unavailable */ class FailedCache implements ICache { + private $visible; + + /** + * FailedCache constructor. + * + * @param bool $visible + */ + public function __construct($visible = true) { + $this->visible = $visible; + } + public function getNumericStorageId() { return -1; @@ -41,7 +52,7 @@ class FailedCache implements ICache { 'size' => 0, 'mimetype' => 'httpd/unix-directory', 'mimepart' => 'httpd', - 'permissions' => Constants::PERMISSION_READ, + 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, 'mtime' => time() ]); } else { diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 6998f94698..6257320ca4 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -31,6 +31,7 @@ namespace OC\Files\Storage; use OC\Files\Filesystem; +use OCA\Files_External\Lib\FailedCache; use OCA\Files_Sharing\ISharedStorage; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; @@ -67,10 +68,16 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { */ private $sourceStorage; + /** + * @var \OCP\ILogger + */ + private $logger; + public function __construct($arguments) { $this->share = $arguments['share']; $this->ownerView = $arguments['ownerView']; $this->user = $arguments['user']; + $this->logger = \OC::$server->getLogger(); } private function init() { @@ -78,15 +85,19 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { return; } $this->initialized = true; - Filesystem::initMountPoints($this->share['uid_owner']); - $sourcePath = $this->ownerView->getPath($this->share['file_source']); - list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath); - $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath); + try { + Filesystem::initMountPoints($this->share['uid_owner']); + $sourcePath = $this->ownerView->getPath($this->share['file_source']); + 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() { $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) { $this->init(); + if (is_null($this->sourceStorage)) { + return new FailedCache(false); + } if (!$storage) { $storage = $this; } From a8db587b1f036bba917288372405d8d830faee54 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 10 Mar 2016 13:38:48 +0100 Subject: [PATCH 2/2] move failedstorage to core --- apps/files_external/lib/config/configadapter.php | 2 +- apps/files_sharing/lib/sharedstorage.php | 2 +- .../lib => lib/private/files/cache}/failedcache.php | 4 ++-- .../lib => lib/private/files/storage}/failedstorage.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename {apps/files_external/lib => lib/private/files/cache}/failedcache.php (96%) rename {apps/files_external/lib => lib/private/files/storage}/failedstorage.php (99%) diff --git a/apps/files_external/lib/config/configadapter.php b/apps/files_external/lib/config/configadapter.php index d85e0f4563..a19a111d3d 100644 --- a/apps/files_external/lib/config/configadapter.php +++ b/apps/files_external/lib/config/configadapter.php @@ -34,7 +34,7 @@ use OCP\IUser; use OCA\Files_external\Service\UserStoragesService; use OCA\Files_External\Service\UserGlobalStoragesService; use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Lib\FailedStorage; +use OC\Files\Storage\FailedStorage; use OCP\Files\StorageNotAvailableException; /** diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 6257320ca4..8f4888d20e 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -31,7 +31,7 @@ namespace OC\Files\Storage; use OC\Files\Filesystem; -use OCA\Files_External\Lib\FailedCache; +use OC\Files\Cache\FailedCache; use OCA\Files_Sharing\ISharedStorage; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; diff --git a/apps/files_external/lib/failedcache.php b/lib/private/files/cache/failedcache.php similarity index 96% rename from apps/files_external/lib/failedcache.php rename to lib/private/files/cache/failedcache.php index 2fddb3eca8..0386ba3ca3 100644 --- a/apps/files_external/lib/failedcache.php +++ b/lib/private/files/cache/failedcache.php @@ -19,9 +19,8 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\Cache; -use OC\Files\Cache\CacheEntry; use OCP\Constants; use OCP\Files\Cache\ICache; @@ -29,6 +28,7 @@ use OCP\Files\Cache\ICache; * Storage placeholder to represent a missing precondition, storage unavailable */ class FailedCache implements ICache { + /** @var bool whether to show the failed storage in the ui */ private $visible; /** diff --git a/apps/files_external/lib/failedstorage.php b/lib/private/files/storage/failedstorage.php similarity index 99% rename from apps/files_external/lib/failedstorage.php rename to lib/private/files/storage/failedstorage.php index 20cf43d74b..df7f76856d 100644 --- a/apps/files_external/lib/failedstorage.php +++ b/lib/private/files/storage/failedstorage.php @@ -20,10 +20,10 @@ * */ -namespace OCA\Files_External\Lib; +namespace OC\Files\Storage; +use OC\Files\Cache\FailedCache; use \OCP\Lock\ILockingProvider; -use \OC\Files\Storage\Common; use \OCP\Files\StorageNotAvailableException; /**