diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-07-02 18:15:58 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-07-02 18:15:58 +0200 |
commit | f4eb90e22965752616051cad0899dc55b4b69506 (patch) | |
tree | 3f7f2b53dad157185d9ad110604ea7056601881f /lib | |
parent | ea756a12b0dfdffe7b1bf9a69fb658ebf69db89a (diff) | |
parent | edb67f9f4dc8d3c028ba6f2d157d2174fb40aba8 (diff) | |
download | nextcloud-server-f4eb90e22965752616051cad0899dc55b4b69506.tar.gz nextcloud-server-f4eb90e22965752616051cad0899dc55b4b69506.zip |
Merge pull request #9311 from owncloud/storage-not-available
Handle storages not being available in webui and webdav
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/connector/sabre/objecttree.php | 10 | ||||
-rw-r--r-- | lib/private/files/mount/manager.php | 4 | ||||
-rw-r--r-- | lib/private/files/storage/dav.php | 44 | ||||
-rw-r--r-- | lib/public/files/storageinvalidexception.php | 22 | ||||
-rw-r--r-- | lib/public/files/storagenotavailableexception.php | 22 |
5 files changed, 84 insertions, 18 deletions
diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php index 54596db3c47..d7a96cfc88e 100644 --- a/lib/private/connector/sabre/objecttree.php +++ b/lib/private/connector/sabre/objecttree.php @@ -11,6 +11,8 @@ namespace OC\Connector\Sabre; use OC\Files\FileInfo; use OC\Files\Filesystem; use OC\Files\Mount\MoveableMount; +use OCP\Files\StorageInvalidException; +use OCP\Files\StorageNotAvailableException; class ObjectTree extends \Sabre\DAV\ObjectTree { @@ -83,7 +85,13 @@ class ObjectTree extends \Sabre\DAV\ObjectTree { } } else { // read from cache - $info = $this->fileView->getFileInfo($path); + try { + $info = $this->fileView->getFileInfo($path); + } catch (StorageNotAvailableException $e) { + throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage not available'); + } catch (StorageInvalidException $e){ + throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid'); + } } if (!$info) { diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php index 45a9f339fba..e5180cfe173 100644 --- a/lib/private/files/mount/manager.php +++ b/lib/private/files/mount/manager.php @@ -27,6 +27,10 @@ class Manager { * @param string $mountPoint */ public function removeMount($mountPoint) { + $mountPoint = Filesystem::normalizePath($mountPoint); + if (strlen($mountPoint) > 1) { + $mountPoint .= '/'; + } unset($this->mounts[$mountPoint]); } diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 8b97f750204..726688fe444 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -8,6 +8,9 @@ namespace OC\Files\Storage; +use OCP\Files\StorageNotAvailableException; +use Sabre\DAV\Exception; + class DAV extends \OC\Files\Storage\Common { protected $password; protected $user; @@ -463,29 +466,36 @@ class DAV extends \OC\Files\Storage\Common { * * @param string $path * @param int $time + * @throws \OCP\Files\StorageNotAvailableException * @return bool */ public function hasUpdated($path, $time) { $this->init(); - $response = $this->client->propfind($this->encodePath($path), array( - '{DAV:}getlastmodified', - '{DAV:}getetag', - '{http://owncloud.org/ns}permissions' - )); - if (isset($response['{DAV:}getetag'])) { - $cachedData = $this->getCache()->get($path); - $etag = trim($response['{DAV:}getetag'], '"'); - if ($cachedData['etag'] !== $etag) { - return true; - } else if (isset($response['{http://owncloud.org/ns}permissions'])) { - $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']); - return $permissions !== $cachedData['permissions']; + try { + $response = $this->client->propfind($this->encodePath($path), array( + '{DAV:}getlastmodified', + '{DAV:}getetag', + '{http://owncloud.org/ns}permissions' + )); + if (isset($response['{DAV:}getetag'])) { + $cachedData = $this->getCache()->get($path); + $etag = trim($response['{DAV:}getetag'], '"'); + if ($cachedData['etag'] !== $etag) { + return true; + } else if (isset($response['{http://owncloud.org/ns}permissions'])) { + $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']); + return $permissions !== $cachedData['permissions']; + } else { + return false; + } } else { - return false; + $remoteMtime = strtotime($response['{DAV:}getlastmodified']); + return $remoteMtime > $time; } - } else { - $remoteMtime = strtotime($response['{DAV:}getlastmodified']); - return $remoteMtime > $time; + } catch (Exception\NotFound $e) { + return false; + } catch (Exception $e) { + throw new StorageNotAvailableException(); } } } diff --git a/lib/public/files/storageinvalidexception.php b/lib/public/files/storageinvalidexception.php new file mode 100644 index 00000000000..7419ccc1d11 --- /dev/null +++ b/lib/public/files/storageinvalidexception.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/AlreadyExistsException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Storage has invalid configuration + */ +class StorageInvalidException extends \Exception { +} diff --git a/lib/public/files/storagenotavailableexception.php b/lib/public/files/storagenotavailableexception.php new file mode 100644 index 00000000000..b526cb4ea0f --- /dev/null +++ b/lib/public/files/storagenotavailableexception.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/AlreadyExistsException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Storage is temporarily not available + */ +class StorageNotAvailableException extends \Exception { +} |