-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Handle invalid ext storage backend to keep mount point visible #26539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
| /** | ||
| * @author Vincent Petry <[email protected]> | ||
| * | ||
| * @copyright Copyright (c) 2017, ownCloud GmbH. | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
|
|
||
| namespace OC\Files\External; | ||
|
|
||
| use OCP\Files\StorageNotAvailableException; | ||
| use OC\Files\Storage\FailedStorage; | ||
|
|
||
| class InvalidStorage extends FailedStorage { | ||
| public function __construct($params) { | ||
| throw new StorageNotAvailableException(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
| /** | ||
| * @author Vincent Petry <[email protected]> | ||
| * | ||
| * @copyright Copyright (c) 2017, ownCloud GmbH. | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
|
|
||
| namespace OCP\Files\External\Auth; | ||
|
|
||
| /** | ||
| * Invalid authentication representing an auth mechanism | ||
| * that could not be resolved | ||
| * | ||
| * @since 10.0.5 | ||
| */ | ||
| class InvalidAuth extends AuthMechanism { | ||
|
|
||
| /** | ||
| * Constructs a new InvalidAuth with the id of the invalid auth | ||
| * for display purposes | ||
| * | ||
| * @param string $invalidId invalid id | ||
| * | ||
| * @since 10.0.5 | ||
| */ | ||
| public function __construct($invalidId) { | ||
| $this->setIdentifier($invalidId) | ||
| ->setScheme(self::SCHEME_NULL) | ||
| ->setText('Unknown auth mechanism backend ' . $invalidId) | ||
| ; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
| /** | ||
| * @author Vincent Petry <[email protected]> | ||
| * | ||
| * @copyright Copyright (c) 2017, ownCloud GmbH. | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
|
|
||
| namespace OCP\Files\External\Backend; | ||
|
|
||
| use \OCP\IL10N; | ||
|
|
||
| /** | ||
| * Invalid storage backend representing a backend | ||
| * that could not be resolved | ||
| * | ||
| * @since 10.0.5 | ||
| */ | ||
| class InvalidBackend extends Backend { | ||
|
|
||
| /** @var string Invalid backend id */ | ||
| private $invalidId; | ||
|
|
||
| /** | ||
| * Constructs a new InvalidBackend with the id of the invalid backend | ||
| * for display purposes | ||
| * | ||
| * @param string $invalidId id of the backend that did not exist | ||
| * | ||
| * @since 10.0.5 | ||
| */ | ||
| function __construct($invalidId) { | ||
| $this->invalidId = $invalidId; | ||
| $this->setIdentifier($invalidId) | ||
| ->setStorageClass('\OC\Files\External\InvalidStorage') | ||
| ->setText('Unknown storage backend ' . $invalidId) | ||
| ; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the invalid backend id | ||
| * | ||
| * @return string invalid backend id | ||
| * | ||
| * @since 10.0.5 | ||
| */ | ||
| public function getInvalidId() { | ||
| return $this->invalidId; | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
| /** | ||
| * @author Vincent Petry <[email protected]> | ||
| * | ||
| * @copyright Copyright (c) 2017, ownCloud GmbH. | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
| namespace Test\Files\External; | ||
|
|
||
| use Test\TestCase; | ||
| use OC\Files\External\InvalidStorage; | ||
|
|
||
| class InvalidStorageTest extends TestCase { | ||
|
|
||
| /** | ||
| * @expectedException OCP\Files\StorageNotAvailableException | ||
| */ | ||
| public function testCannotInstantiate() { | ||
| new InvalidStorage([]); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems too "artificial" for me. Creating a class that would throw an exception in the constructor implies that you want to throw the exception in the first place, which makes me wonder why do we need to create a class for that.
It probably makes more sense if the exception is thrown in specific methods even if those methods are almost all of them. My point is that the InvalidStorage should behave as another storage, but that exception doesn't allow it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual reason is that at the location where we specify the class name we don't actually instantiate it. Remember that the external storage backend class must specify a name for the storage class to be instantiated, it doesn't instantiate it itself, but MountPoint->createStorage will instantiate it later. Throwing an exception in the constructor is to make sure this never happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My worry is that this is something that wasn't originally planned.
Due to there isn't an oficial storage factory, other apps like WND have to create the storages on their own. Throwing the exception like that will likely affect them even if the storage won't be used. I'll have to recheck the behaviour.
Creating the storage and throwing the exception in the rest of the methods seems a more compatible option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, it seems WND will check the backend class and won't try to create an storage instance if it isn't for the WND backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a
StorageFactoryclass: https://github.com/owncloud/core/blob/v10.0.3/lib/private/Files/Storage/StorageFactory.php and here is the code that instantiates storages: https://github.com/owncloud/core/blob/v10.0.3/lib/private/Files/Mount/MountPoint.php#L138 (the $loader is actually an instance ofStorageFactory.In general third party apps should never instantiate the storage class themselves.
The use case of this InvalidStorage class should also never be accessible for apps as it's designed for use by core when accessing a storage for which the actual storage class does not exist due to the app being disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm out of arguments against it, but it still feels like adding tomato to the spaghetti code... 🤕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahaha, it does.
Unfortunately the backends came after the storages. If we designed storages to have backends first, we could have designed it so that the backend is responsible of instantiating storages, in which case this mess above wouldn't required.