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 | |
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')
-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 | ||||
-rw-r--r-- | lib/private/hooks/basicemitter.php | 78 | ||||
-rw-r--r-- | lib/private/hooks/emitter.php | 4 | ||||
-rw-r--r-- | lib/private/hooks/emittertrait.php | 103 | ||||
-rw-r--r-- | lib/private/hooks/forwardingemitter.php | 4 | ||||
-rw-r--r-- | lib/private/hooks/legacyemitter.php | 2 | ||||
-rw-r--r-- | lib/private/hooks/publicemitter.php | 2 | ||||
-rw-r--r-- | lib/private/repair.php | 2 | ||||
-rw-r--r-- | lib/private/user/session.php | 4 |
11 files changed, 163 insertions, 96 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); } diff --git a/lib/private/hooks/basicemitter.php b/lib/private/hooks/basicemitter.php index 03d0d1d74ca..ae0f96fbc8c 100644 --- a/lib/private/hooks/basicemitter.php +++ b/lib/private/hooks/basicemitter.php @@ -23,81 +23,5 @@ namespace OC\Hooks; abstract class BasicEmitter implements Emitter { - - /** - * @var (callable[])[] $listeners - */ - protected $listeners = array(); - - /** - * @param string $scope - * @param string $method - * @param callable $callback - */ - public function listen($scope, $method, $callback) { - $eventName = $scope . '::' . $method; - if (!isset($this->listeners[$eventName])) { - $this->listeners[$eventName] = array(); - } - if (array_search($callback, $this->listeners[$eventName]) === false) { - $this->listeners[$eventName][] = $callback; - } - } - - /** - * @param string $scope optional - * @param string $method optional - * @param callable $callback optional - */ - public function removeListener($scope = null, $method = null, $callback = null) { - $names = array(); - $allNames = array_keys($this->listeners); - if ($scope and $method) { - $name = $scope . '::' . $method; - if (isset($this->listeners[$name])) { - $names[] = $name; - } - } elseif ($scope) { - foreach ($allNames as $name) { - $parts = explode('::', $name, 2); - if ($parts[0] == $scope) { - $names[] = $name; - } - } - } elseif ($method) { - foreach ($allNames as $name) { - $parts = explode('::', $name, 2); - if ($parts[1] == $method) { - $names[] = $name; - } - } - } else { - $names = $allNames; - } - - foreach ($names as $name) { - if ($callback) { - $index = array_search($callback, $this->listeners[$name]); - if ($index !== false) { - unset($this->listeners[$name][$index]); - } - } else { - $this->listeners[$name] = array(); - } - } - } - - /** - * @param string $scope - * @param string $method - * @param array $arguments optional - */ - protected function emit($scope, $method, $arguments = array()) { - $eventName = $scope . '::' . $method; - if (isset($this->listeners[$eventName])) { - foreach ($this->listeners[$eventName] as $callback) { - call_user_func_array($callback, $arguments); - } - } - } + use EmitterTrait; } diff --git a/lib/private/hooks/emitter.php b/lib/private/hooks/emitter.php index 895bd2d9cac..bea3f289b8d 100644 --- a/lib/private/hooks/emitter.php +++ b/lib/private/hooks/emitter.php @@ -37,7 +37,7 @@ interface Emitter { * @param callable $callback * @return void */ - public function listen($scope, $method, $callback); + public function listen($scope, $method, callable $callback); /** * @param string $scope optional @@ -45,5 +45,5 @@ interface Emitter { * @param callable $callback optional * @return void */ - public function removeListener($scope = null, $method = null, $callback = null); + public function removeListener($scope = null, $method = null, callable $callback = null); } diff --git a/lib/private/hooks/emittertrait.php b/lib/private/hooks/emittertrait.php new file mode 100644 index 00000000000..5d471a3f553 --- /dev/null +++ b/lib/private/hooks/emittertrait.php @@ -0,0 +1,103 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @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\Hooks; + +trait EmitterTrait { + + /** + * @var (callable[])[] $listeners + */ + protected $listeners = array(); + + /** + * @param string $scope + * @param string $method + * @param callable $callback + */ + public function listen($scope, $method, callable $callback) { + $eventName = $scope . '::' . $method; + if (!isset($this->listeners[$eventName])) { + $this->listeners[$eventName] = array(); + } + if (array_search($callback, $this->listeners[$eventName], true) === false) { + $this->listeners[$eventName][] = $callback; + } + } + + /** + * @param string $scope optional + * @param string $method optional + * @param callable $callback optional + */ + public function removeListener($scope = null, $method = null, callable $callback = null) { + $names = array(); + $allNames = array_keys($this->listeners); + if ($scope and $method) { + $name = $scope . '::' . $method; + if (isset($this->listeners[$name])) { + $names[] = $name; + } + } elseif ($scope) { + foreach ($allNames as $name) { + $parts = explode('::', $name, 2); + if ($parts[0] == $scope) { + $names[] = $name; + } + } + } elseif ($method) { + foreach ($allNames as $name) { + $parts = explode('::', $name, 2); + if ($parts[1] == $method) { + $names[] = $name; + } + } + } else { + $names = $allNames; + } + + foreach ($names as $name) { + if ($callback) { + $index = array_search($callback, $this->listeners[$name], true); + if ($index !== false) { + unset($this->listeners[$name][$index]); + } + } else { + $this->listeners[$name] = array(); + } + } + } + + /** + * @param string $scope + * @param string $method + * @param array $arguments optional + */ + protected function emit($scope, $method, array $arguments = array()) { + $eventName = $scope . '::' . $method; + if (isset($this->listeners[$eventName])) { + foreach ($this->listeners[$eventName] as $callback) { + call_user_func_array($callback, $arguments); + } + } + } +} diff --git a/lib/private/hooks/forwardingemitter.php b/lib/private/hooks/forwardingemitter.php index 853004310fb..90c1970f480 100644 --- a/lib/private/hooks/forwardingemitter.php +++ b/lib/private/hooks/forwardingemitter.php @@ -40,7 +40,7 @@ abstract class ForwardingEmitter extends BasicEmitter { * @param string $method * @param callable $callback */ - public function listen($scope, $method, $callback) { + public function listen($scope, $method, callable $callback) { parent::listen($scope, $method, $callback); foreach ($this->forwardEmitters as $emitter) { $emitter->listen($scope, $method, $callback); @@ -50,7 +50,7 @@ abstract class ForwardingEmitter extends BasicEmitter { /** * @param \OC\Hooks\Emitter $emitter */ - protected function forward($emitter) { + protected function forward(Emitter $emitter) { $this->forwardEmitters[] = $emitter; //forward all previously connected hooks diff --git a/lib/private/hooks/legacyemitter.php b/lib/private/hooks/legacyemitter.php index b0912d740d2..b28854f4638 100644 --- a/lib/private/hooks/legacyemitter.php +++ b/lib/private/hooks/legacyemitter.php @@ -23,7 +23,7 @@ namespace OC\Hooks; abstract class LegacyEmitter extends BasicEmitter { - protected function emit($scope, $method, $arguments = array()) { + protected function emit($scope, $method, array $arguments = array()) { \OC_Hook::emit($scope, $method, $arguments); parent::emit($scope, $method, $arguments); } diff --git a/lib/private/hooks/publicemitter.php b/lib/private/hooks/publicemitter.php index 71641c9d5e0..12de07b27c7 100644 --- a/lib/private/hooks/publicemitter.php +++ b/lib/private/hooks/publicemitter.php @@ -28,7 +28,7 @@ class PublicEmitter extends BasicEmitter { * @param string $method * @param array $arguments optional */ - public function emit($scope, $method, $arguments = array()) { + public function emit($scope, $method, array $arguments = array()) { parent::emit($scope, $method, $arguments); } } diff --git a/lib/private/repair.php b/lib/private/repair.php index c690fe4a8cd..43350995beb 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -142,7 +142,7 @@ class Repair extends BasicEmitter { * * Re-declared as public to allow invocation from within the closure above in php 5.3 */ - public function emit($scope, $method, $arguments = array()) { + public function emit($scope, $method, array $arguments = array()) { parent::emit($scope, $method, $arguments); } } diff --git a/lib/private/user/session.php b/lib/private/user/session.php index a66ae6bd8ad..75a884fb452 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -81,7 +81,7 @@ class Session implements IUserSession, Emitter { * @param string $method * @param callable $callback */ - public function listen($scope, $method, $callback) { + public function listen($scope, $method, callable $callback) { $this->manager->listen($scope, $method, $callback); } @@ -90,7 +90,7 @@ class Session implements IUserSession, Emitter { * @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->manager->removeListener($scope, $method, $callback); } |