-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add a public api for apps to add mounts #12577
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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,44 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace OCA\Files_External\Config; | ||
|
||
use OC\Files\Mount\MountPoint; | ||
use OCP\Files\Storage\IStorageFactory; | ||
use OCA\Files_External\PersonalMount; | ||
use OCP\Files\Config\IMountProvider; | ||
use OCP\IUser; | ||
|
||
/** | ||
* Make the old files_external config work with the new public mount config api | ||
*/ | ||
class ConfigAdapter implements IMountProvider { | ||
/** | ||
* Get all mountpoints applicable for the user | ||
* | ||
* @param \OCP\IUser $user | ||
* @param \OCP\Files\Storage\IStorageFactory $loader | ||
* @return \OCP\Files\Mount\IMountPoint[] | ||
*/ | ||
public function getMountsForUser(IUser $user, IStorageFactory $loader) { | ||
$mountPoints = \OC_Mount_Config::getAbsoluteMountPoints($user->getUID()); | ||
$mounts = array(); | ||
foreach ($mountPoints as $mountPoint => $options) { | ||
if (isset($options['options']['objectstore'])) { | ||
$objectClass = $options['options']['objectstore']['class']; | ||
$options['options']['objectstore'] = new $objectClass($options['options']['objectstore']); | ||
} | ||
if (isset($options['personal']) && $options['personal']) { | ||
$mounts[] = new PersonalMount($options['class'], $mountPoint, $options['options'], $loader); | ||
} else { | ||
$mounts[] = new MountPoint($options['class'], $mountPoint, $options['options'], $loader); | ||
} | ||
} | ||
return $mounts; | ||
} | ||
} |
This file contains 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 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 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 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 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,55 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace OC\Files\Config; | ||
|
||
use OCP\Files\Config\IMountProviderCollection; | ||
use OCP\Files\Config\IMountProvider; | ||
use OCP\Files\Storage\IStorageFactory; | ||
use OCP\IUser; | ||
|
||
class MountProviderCollection implements IMountProviderCollection { | ||
/** | ||
* @var \OCP\Files\Config\IMountProvider[] | ||
*/ | ||
private $providers = array(); | ||
|
||
/** | ||
* @var \OCP\Files\Storage\IStorageFactory | ||
*/ | ||
private $loader; | ||
|
||
/** | ||
* @param \OCP\Files\Storage\IStorageFactory $loader | ||
*/ | ||
public function __construct(IStorageFactory $loader) { | ||
$this->loader = $loader; | ||
} | ||
|
||
/** | ||
* Get all configured mount points for the user | ||
* | ||
* @param \OCP\IUser $user | ||
* @return \OCP\Files\Mount\IMountPoint[] | ||
*/ | ||
public function getMountsForUser(IUser $user) { | ||
$loader = $this->loader; | ||
return array_reduce($this->providers, function ($mounts, IMountProvider $provider) use ($user, $loader) { | ||
return array_merge($mounts, $provider->getMountsForUser($user, $loader)); | ||
}, array()); | ||
} | ||
|
||
/** | ||
* Add a provider for mount points | ||
* | ||
* @param \OCP\Files\Config\IMountProvider $provider | ||
*/ | ||
public function registerProvider(IMountProvider $provider) { | ||
$this->providers[] = $provider; | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
|
||
namespace OC\Files; | ||
|
||
use OC\Files\Storage\Loader; | ||
use OC\Files\Storage\StorageFactory; | ||
|
||
class Filesystem { | ||
|
||
|
@@ -165,7 +165,7 @@ class Filesystem { | |
const signal_param_users = 'users'; | ||
|
||
/** | ||
* @var \OC\Files\Storage\Loader $loader | ||
* @var \OC\Files\Storage\StorageFactory $loader | ||
*/ | ||
private static $loader; | ||
|
||
|
@@ -183,7 +183,7 @@ public static function addStorageWrapper($wrapperName, $wrapper) { | |
|
||
public static function getLoader() { | ||
if (!self::$loader) { | ||
self::$loader = new Loader(); | ||
self::$loader = new StorageFactory(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this a |
||
} | ||
return self::$loader; | ||
} | ||
|
@@ -250,7 +250,7 @@ public static function getStorage($mountPoint) { | |
|
||
/** | ||
* @param string $id | ||
* @return Mount\Mount[] | ||
* @return Mount\MountPoint[] | ||
*/ | ||
public static function getMountByStorageId($id) { | ||
if (!self::$mounts) { | ||
|
@@ -261,7 +261,7 @@ public static function getMountByStorageId($id) { | |
|
||
/** | ||
* @param int $id | ||
* @return Mount\Mount[] | ||
* @return Mount\MountPoint[] | ||
*/ | ||
public static function getMountByNumericId($id) { | ||
if (!self::$mounts) { | ||
|
@@ -370,6 +370,11 @@ public static function initMountPoints($user = '') { | |
self::mountCacheDir($user); | ||
|
||
// Chance to mount for other storages | ||
if($userObject) { | ||
$mountConfigManager = \OC::$server->getMountProviderCollection(); | ||
$mounts = $mountConfigManager->getMountsForUser($userObject); | ||
array_walk($mounts, array(self::$mounts, 'addMount')); | ||
} | ||
\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root)); | ||
} | ||
|
||
|
@@ -447,7 +452,7 @@ static public function mount($class, $arguments, $mountpoint) { | |
if (!self::$mounts) { | ||
\OC_Util::setupFS(); | ||
} | ||
$mount = new Mount\Mount($class, $mountpoint, $arguments, self::getLoader()); | ||
$mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader()); | ||
self::$mounts->addMount($mount); | ||
} | ||
|
||
|
This file contains 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 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
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.
I wonder, are PersonalMount and MountPoint public classes ? Or should we also "hide" them behind factories ?
In general it feels a bit uncomfortable when I see mountpoints instantiated directly like this.
What do you think ?
Also: will other external storage apps also need to instantiate
new MountPoint()
directly ? Do they need to implement their own IMountPoint ?Edit: wording
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.
Current mount providers need to instantiate the mounts themselves since the class used determines behavior such as mount moving