From 6990100e6ed6d1efe48e2688331df5ce364f9fd5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 3 Mar 2016 14:19:34 +0100 Subject: [PATCH 1/2] allow availability recheck for external storages --- .../files_external/lib/config/configadapter.php | 3 ++- .../files/storage/wrapper/availability.php | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/files_external/lib/config/configadapter.php b/apps/files_external/lib/config/configadapter.php index 51c2debd72..f097d55a31 100644 --- a/apps/files_external/lib/config/configadapter.php +++ b/apps/files_external/lib/config/configadapter.php @@ -23,6 +23,7 @@ namespace OCA\Files_External\Config; +use OC\Files\Storage\Wrapper\Availability; use OCA\Files_external\Migration\StorageMigrator; use OCP\Files\Storage; use OC\Files\Mount\MountPoint; @@ -132,7 +133,7 @@ class ConfigAdapter implements IMountProvider { try { $availability = $impl->getAvailability(); - if (!$availability['available']) { + if (!$availability['available'] && !Availability::shouldRecheck($availability)) { $impl = new FailedStorage(['exception' => null]); } } catch (\Exception $e) { diff --git a/lib/private/files/storage/wrapper/availability.php b/lib/private/files/storage/wrapper/availability.php index 55ddb0d5e8..0ed31ba854 100644 --- a/lib/private/files/storage/wrapper/availability.php +++ b/lib/private/files/storage/wrapper/availability.php @@ -29,6 +29,16 @@ namespace OC\Files\Storage\Wrapper; class Availability extends Wrapper { const RECHECK_TTL_SEC = 600; // 10 minutes + public static function shouldRecheck($availability) { + if (!$availability['available']) { + // trigger a recheck if TTL reached + if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { + return true; + } + } + return false; + } + /** * @return bool */ @@ -47,11 +57,8 @@ class Availability extends Wrapper { */ private function isAvailable() { $availability = $this->getAvailability(); - if (!$availability['available']) { - // trigger a recheck if TTL reached - if ((time() - $availability['last_checked']) > self::RECHECK_TTL_SEC) { - return $this->updateAvailability(); - } + if (self::shouldRecheck($availability)) { + return $this->updateAvailability(); } return $availability['available']; } From 4255dd2b396050e757f77db86063f0f1420a87d5 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 2 Mar 2016 12:17:14 +0100 Subject: [PATCH 2/2] Properly set exception in FailedStorage --- apps/files_external/lib/config/configadapter.php | 5 ++++- apps/files_external/lib/failedstorage.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/files_external/lib/config/configadapter.php b/apps/files_external/lib/config/configadapter.php index f097d55a31..d85e0f4563 100644 --- a/apps/files_external/lib/config/configadapter.php +++ b/apps/files_external/lib/config/configadapter.php @@ -35,6 +35,7 @@ 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 OCP\Files\StorageNotAvailableException; /** * Make the old files_external config work with the new public mount config api @@ -134,7 +135,9 @@ class ConfigAdapter implements IMountProvider { try { $availability = $impl->getAvailability(); if (!$availability['available'] && !Availability::shouldRecheck($availability)) { - $impl = new FailedStorage(['exception' => null]); + $impl = new FailedStorage([ + 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storage->getId() . ' is not available') + ]); } } catch (\Exception $e) { // propagate exception into filesystem diff --git a/apps/files_external/lib/failedstorage.php b/apps/files_external/lib/failedstorage.php index 928d09e20f..20cf43d74b 100644 --- a/apps/files_external/lib/failedstorage.php +++ b/apps/files_external/lib/failedstorage.php @@ -39,6 +39,9 @@ class FailedStorage extends Common { */ public function __construct($params) { $this->e = $params['exception']; + if (!$this->e) { + throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor'); + } } public function getId() {