diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-06-08 13:42:02 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-06-08 13:42:02 +0200 |
commit | a968b8409d153257d63cc78f71139303557f4617 (patch) | |
tree | 6b6cdf36c6df99f0f5ef1999814b2645a4edc719 /lib/private/files | |
parent | f051b7381ba00d538dd5ad0b1ba5b016d4aa62b1 (diff) | |
parent | a9455be14a36013adead81de06e3799e6e7efb9b (diff) | |
download | nextcloud-server-a968b8409d153257d63cc78f71139303557f4617.tar.gz nextcloud-server-a968b8409d153257d63cc78f71139303557f4617.zip |
Merge pull request #16158 from owncloud/mountprovider-after-setup
Call newly registered mount providers after the filesystem is setup
Diffstat (limited to 'lib/private/files')
-rw-r--r-- | lib/private/files/config/mountprovidercollection.php | 7 | ||||
-rw-r--r-- | lib/private/files/filesystem.php | 49 | ||||
-rw-r--r-- | lib/private/files/node/root.php | 4 |
3 files changed, 50 insertions, 10 deletions
diff --git a/lib/private/files/config/mountprovidercollection.php b/lib/private/files/config/mountprovidercollection.php index 326d72001d0..a14a6ef796f 100644 --- a/lib/private/files/config/mountprovidercollection.php +++ b/lib/private/files/config/mountprovidercollection.php @@ -22,12 +22,16 @@ namespace OC\Files\Config; +use OC\Hooks\Emitter; +use OC\Hooks\EmitterTrait; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\IUser; -class MountProviderCollection implements IMountProviderCollection { +class MountProviderCollection implements IMountProviderCollection, Emitter { + use EmitterTrait; + /** * @var \OCP\Files\Config\IMountProvider[] */ @@ -65,5 +69,6 @@ class MountProviderCollection implements IMountProviderCollection { */ public function registerProvider(IMountProvider $provider) { $this->providers[] = $provider; + $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]); } } diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 10c64e1301a..212deb24b7a 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -59,7 +59,11 @@ namespace OC\Files; +use OC\Cache\File; +use OC\Files\Config\MountProviderCollection; use OC\Files\Storage\StorageFactory; +use OCP\Files\Config\IMountProvider; +use OCP\IUserManager; class Filesystem { @@ -78,6 +82,8 @@ class Filesystem { static private $normalizedPathCache = array(); + static private $listeningForProviders = false; + /** * classname which used for hooks handling * used as signalclass in OC_Hooks::emit() @@ -371,14 +377,15 @@ class Filesystem { $root = \OC_User::getHome($user); - $userObject = \OC_User::getManager()->get($user); + $userManager = \OC::$server->getUserManager(); + $userObject = $userManager->get($user); if (is_null($userObject)) { - \OCP\Util::writeLog('files', ' Backends provided no user object for '.$user, \OCP\Util::ERROR); + \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); throw new \OC\User\NoUserException(); } - $homeStorage = \OC_Config::getValue( 'objectstore' ); + $homeStorage = \OC_Config::getValue('objectstore'); if (!empty($homeStorage)) { // sanity checks if (empty($homeStorage['class'])) { @@ -412,16 +419,41 @@ class Filesystem { self::mountCacheDir($user); // Chance to mount for other storages - if($userObject) { - $mountConfigManager = \OC::$server->getMountProviderCollection(); + /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ + $mountConfigManager = \OC::$server->getMountProviderCollection(); + if ($userObject) { $mounts = $mountConfigManager->getMountsForUser($userObject); array_walk($mounts, array(self::$mounts, 'addMount')); } + + self::listenForNewMountProviders($mountConfigManager, $userManager); \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root)); } /** + * Get mounts from mount providers that are registered after setup + * + * @param MountProviderCollection $mountConfigManager + * @param IUserManager $userManager + */ + private static function listenForNewMountProviders(MountProviderCollection $mountConfigManager, IUserManager $userManager) { + if (!self::$listeningForProviders) { + self::$listeningForProviders = true; + $mountConfigManager->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) use ($userManager) { + foreach (Filesystem::$usersSetup as $user => $setup) { + $userObject = $userManager->get($user); + if ($userObject) { + $mounts = $provider->getMountsForUser($userObject, Filesystem::getLoader()); + array_walk($mounts, array(self::$mounts, 'addMount')); + } + } + }); + } + } + + /** * Mounts the cache directory + * * @param string $user user name */ private static function mountCacheDir($user) { @@ -455,6 +487,7 @@ class Filesystem { /** * get the relative path of the root data directory for the current user + * * @return string * * Returns path like /admin/files @@ -537,7 +570,7 @@ class Filesystem { if (!$path || $path[0] !== '/') { $path = '/' . $path; } - if (strpos($path, '/../') !== FALSE || strrchr($path, '/') === '/..') { + if (strpos($path, '/../') !== false || strrchr($path, '/') === '/..') { return false; } return true; @@ -577,6 +610,7 @@ class Filesystem { /** * check if the directory should be ignored when scanning * NOTE: the special directories . and .. would cause never ending recursion + * * @param String $dir * @return boolean */ @@ -745,6 +779,7 @@ class Filesystem { /** * Fix common problems with a file path + * * @param string $path * @param bool $stripTrailingSlash * @param bool $isAbsolutePath @@ -761,7 +796,7 @@ class Filesystem { $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath]); - if(isset(self::$normalizedPathCache[$cacheKey])) { + if (isset(self::$normalizedPathCache[$cacheKey])) { return self::$normalizedPathCache[$cacheKey]; } diff --git a/lib/private/files/node/root.php b/lib/private/files/node/root.php index e47f98b0f27..7ffb3674a8f 100644 --- a/lib/private/files/node/root.php +++ b/lib/private/files/node/root.php @@ -94,7 +94,7 @@ class Root extends Folder implements IRootFolder { * @param string $method * @param callable $callback */ - public function listen($scope, $method, $callback) { + public function listen($scope, $method, callable $callback) { $this->emitter->listen($scope, $method, $callback); } @@ -103,7 +103,7 @@ class Root extends Folder implements IRootFolder { * @param string $method optional * @param callable $callback optional */ - public function removeListener($scope = null, $method = null, $callback = null) { + public function removeListener($scope = null, $method = null, callable $callback = null) { $this->emitter->removeListener($scope, $method, $callback); } |