aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Filesystem.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-03-03 16:36:58 +0100
committerRobin Appelman <robin@icewind.nl>2022-03-04 16:30:12 +0100
commit07a7dcb8249c9e25ea7a702e8c932520e2b32de6 (patch)
tree5334df0f67d810eaf733a713d8ae8545e1b5d4fc /lib/private/Files/Filesystem.php
parentd81713e5c10baf8e14f9a8c4906d0255b18cbb1f (diff)
downloadnextcloud-server-07a7dcb8249c9e25ea7a702e8c932520e2b32de6.tar.gz
nextcloud-server-07a7dcb8249c9e25ea7a702e8c932520e2b32de6.zip
move user mountpoint setup to setupmanager
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Filesystem.php')
-rw-r--r--lib/private/Files/Filesystem.php109
1 files changed, 10 insertions, 99 deletions
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php
index 71a6385bce1..b392b1aa3cb 100644
--- a/lib/private/Files/Filesystem.php
+++ b/lib/private/Files/Filesystem.php
@@ -41,6 +41,7 @@ use OC\Cache\CappedMemoryCache;
use OC\Files\Config\MountProviderCollection;
use OC\Files\Mount\MountPoint;
use OC\Lockdown\Filesystem\NullStorage;
+use OC\User\NoUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
@@ -367,106 +368,16 @@ class Filesystem {
* @throws \OC\User\NoUserException if the user is not available
*/
public static function initMountPoints($user = '') {
- $userManager = \OC::$server->getUserManager();
- if (is_string($user)) {
- if ($user === '') {
- $user = \OC_User::getUser();
- }
-
- $userObject = $userManager->get($user);
- } elseif ($user instanceof IUser) {
- $userObject = $user;
- $user = $userObject->getUID();
+ /** @var IUserManager $userManager */
+ $userManager = \OC::$server->get(IUserManager::class);
+
+ $userObject = ($user instanceof IUser) ? $user : $userManager->get($user);
+ if ($userObject) {
+ /** @var SetupManager $setupManager */
+ $setupManager = \OC::$server->get(SetupManager::class);
+ $setupManager->setupForUser($userObject);
} else {
- $userObject = null;
- }
-
- if ($userObject === null || $user === false || $user === '') {
- throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session');
- }
-
- if (isset(self::$usersSetup[$user])) {
- return;
- }
-
- self::$usersSetup[$user] = true;
-
- if (is_null($userObject)) {
- \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, ILogger::ERROR);
- // reset flag, this will make it possible to rethrow the exception if called again
- unset(self::$usersSetup[$user]);
- throw new \OC\User\NoUserException('Backends provided no user object for ' . $user);
- }
-
- $realUid = $userObject->getUID();
- // workaround in case of different casings
- if ($user !== $realUid) {
- $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50));
- \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, ILogger::WARN);
- $user = $realUid;
-
- // again with the correct casing
- if (isset(self::$usersSetup[$user])) {
- return;
- }
-
- self::$usersSetup[$user] = true;
- }
-
- if (\OC::$server->getLockdownManager()->canAccessFilesystem()) {
- /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */
- $mountConfigManager = \OC::$server->getMountProviderCollection();
-
- // home mounts are handled seperate since we need to ensure this is mounted before we call the other mount providers
- $homeMount = $mountConfigManager->getHomeMountForUser($userObject);
- self::getMountManager()->addMount($homeMount);
-
- if ($homeMount->getStorageRootId() === -1) {
- $homeMount->getStorage()->mkdir('');
- $homeMount->getStorage()->getScanner()->scan('');
- }
-
- \OC\Files\Filesystem::getStorage($user);
-
- // Chance to mount for other storages
- if ($userObject) {
- $mounts = $mountConfigManager->addMountForUser($userObject, self::getMountManager());
- $mounts[] = $homeMount;
- $mountConfigManager->registerMounts($userObject, $mounts);
- }
-
- self::listenForNewMountProviders($mountConfigManager, $userManager);
- } else {
- self::getMountManager()->addMount(new MountPoint(
- new NullStorage([]),
- '/' . $user
- ));
- self::getMountManager()->addMount(new MountPoint(
- new NullStorage([]),
- '/' . $user . '/files'
- ));
- }
- \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user]);
- }
-
- /**
- * 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, [self::$mounts, 'addMount']);
- }
- }
- });
+ throw new NoUserException();
}
}