diff options
Diffstat (limited to 'lib/private/Files/Storage/Wrapper/Availability.php')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Availability.php | 207 |
1 files changed, 100 insertions, 107 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index 5b957ae036b..0c01595d306 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -21,9 +21,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OC\Files\Storage\Wrapper; use OCP\Files\Storage\IStorage; +use OCP\Files\StorageAuthException; +use OCP\Files\StorageNotAvailableException; +use OCP\IConfig; /** * Availability checker for storages @@ -33,6 +37,14 @@ use OCP\Files\Storage\IStorage; class Availability extends Wrapper { const RECHECK_TTL_SEC = 600; // 10 minutes + /** @var IConfig */ + protected $config; + + public function __construct($parameters) { + $this->config = $parameters['config'] ?? \OC::$server->getConfig(); + parent::__construct($parameters); + } + public static function shouldRecheck($availability) { if (!$availability['available']) { // trigger a recheck if TTL reached @@ -72,11 +84,11 @@ class Availability extends Wrapper { } /** - * @throws \OCP\Files\StorageNotAvailableException + * @throws StorageNotAvailableException */ private function checkAvailability() { if (!$this->isAvailable()) { - throw new \OCP\Files\StorageNotAvailableException(); + throw new StorageNotAvailableException(); } } @@ -85,9 +97,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::mkdir($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -96,9 +107,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::rmdir($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -107,9 +117,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::opendir($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -118,9 +127,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::is_dir($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -129,9 +137,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::is_file($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -140,9 +147,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::stat($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -151,9 +157,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::filetype($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -162,9 +167,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::filesize($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -173,9 +177,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::isCreatable($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -184,9 +187,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::isReadable($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -195,9 +197,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::isUpdatable($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -206,9 +207,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::isDeletable($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -217,9 +217,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::isSharable($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -228,9 +227,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::getPermissions($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -242,9 +240,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::file_exists($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -253,9 +250,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::filemtime($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -264,9 +260,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::file_get_contents($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -275,9 +270,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::file_put_contents($path, $data); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -286,9 +280,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::unlink($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -297,9 +290,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::rename($path1, $path2); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -308,9 +300,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::copy($path1, $path2); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -319,9 +310,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::fopen($path, $mode); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -330,9 +320,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::getMimeType($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -341,9 +330,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::hash($type, $path, $raw); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -352,9 +340,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::free_space($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -363,9 +350,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::search($query); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -374,9 +360,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::touch($path, $mtime); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -385,9 +370,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::getLocalFile($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -396,9 +380,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::hasUpdated($path, $time); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -406,9 +389,8 @@ class Availability extends Wrapper { public function getOwner($path) { try { return parent::getOwner($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -417,9 +399,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::getETag($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -428,9 +409,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::getDirectDownload($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -439,9 +419,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -450,9 +429,8 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } @@ -461,9 +439,24 @@ class Availability extends Wrapper { $this->checkAvailability(); try { return parent::getMetaData($path); - } catch (\OCP\Files\StorageNotAvailableException $e) { - $this->setAvailability(false); - throw $e; + } catch (StorageNotAvailableException $e) { + $this->setUnavailable($e); } } + + /** + * @throws StorageNotAvailableException + */ + protected function setUnavailable(StorageNotAvailableException $e) { + $delay = self::RECHECK_TTL_SEC; + if($e instanceof StorageAuthException) { + $delay = max( + // 30min + $this->config->getSystemValueInt('external_storage.auth_availability_delay', 1800), + self::RECHECK_TTL_SEC + ); + } + $this->getStorageCache()->setAvailability(false, $delay); + throw $e; + } } |