Passed
Push — master ( 3b98db...ef9890 )
by Robin
15:39 queued 24s
created
apps/files/lib/Controller/AjaxController.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -33,26 +33,26 @@
 block discarded – undo
33 33
 use OCP\IRequest;
34 34
 
35 35
 class AjaxController extends Controller {
36
-	public function __construct(string $appName, IRequest $request) {
37
-		parent::__construct($appName, $request);
38
-	}
36
+    public function __construct(string $appName, IRequest $request) {
37
+        parent::__construct($appName, $request);
38
+    }
39 39
 
40
-	/**
41
-	 * @NoAdminRequired
42
-	 */
43
-	public function getStorageStats(string $dir = '/'): JSONResponse {
44
-		try {
45
-			return new JSONResponse([
46
-				'status' => 'success',
47
-				'data' => Helper::buildFileStorageStatistics($dir),
48
-			]);
49
-		} catch (NotFoundException $e) {
50
-			return new JSONResponse([
51
-				'status' => 'error',
52
-				'data' => [
53
-					'message' => 'Folder not found'
54
-				],
55
-			]);
56
-		}
57
-	}
40
+    /**
41
+     * @NoAdminRequired
42
+     */
43
+    public function getStorageStats(string $dir = '/'): JSONResponse {
44
+        try {
45
+            return new JSONResponse([
46
+                'status' => 'success',
47
+                'data' => Helper::buildFileStorageStatistics($dir),
48
+            ]);
49
+        } catch (NotFoundException $e) {
50
+            return new JSONResponse([
51
+                'status' => 'error',
52
+                'data' => [
53
+                    'message' => 'Folder not found'
54
+                ],
55
+            ]);
56
+        }
57
+    }
58 58
 }
Please login to merge, or discard this patch.
lib/private/Files/SetupManager.php 2 patches
Indentation   +480 added lines, -480 removed lines patch added patch discarded remove patch
@@ -62,486 +62,486 @@
 block discarded – undo
62 62
 use Psr\Log\LoggerInterface;
63 63
 
64 64
 class SetupManager {
65
-	private bool $rootSetup = false;
66
-	private IEventLogger $eventLogger;
67
-	private MountProviderCollection $mountProviderCollection;
68
-	private IMountManager $mountManager;
69
-	private IUserManager $userManager;
70
-	// List of users for which at least one mount is setup
71
-	private array $setupUsers = [];
72
-	// List of users for which all mounts are setup
73
-	private array $setupUsersComplete = [];
74
-	/** @var array<string, string[]> */
75
-	private array $setupUserMountProviders = [];
76
-	private IEventDispatcher $eventDispatcher;
77
-	private IUserMountCache $userMountCache;
78
-	private ILockdownManager $lockdownManager;
79
-	private IUserSession $userSession;
80
-	private ICache $cache;
81
-	private LoggerInterface $logger;
82
-	private IConfig $config;
83
-	private bool $listeningForProviders;
84
-
85
-	public function __construct(
86
-		IEventLogger $eventLogger,
87
-		MountProviderCollection $mountProviderCollection,
88
-		IMountManager $mountManager,
89
-		IUserManager $userManager,
90
-		IEventDispatcher $eventDispatcher,
91
-		IUserMountCache $userMountCache,
92
-		ILockdownManager $lockdownManager,
93
-		IUserSession $userSession,
94
-		ICacheFactory $cacheFactory,
95
-		LoggerInterface $logger,
96
-		IConfig $config
97
-	) {
98
-		$this->eventLogger = $eventLogger;
99
-		$this->mountProviderCollection = $mountProviderCollection;
100
-		$this->mountManager = $mountManager;
101
-		$this->userManager = $userManager;
102
-		$this->eventDispatcher = $eventDispatcher;
103
-		$this->userMountCache = $userMountCache;
104
-		$this->lockdownManager = $lockdownManager;
105
-		$this->logger = $logger;
106
-		$this->userSession = $userSession;
107
-		$this->cache = $cacheFactory->createDistributed('setupmanager::');
108
-		$this->listeningForProviders = false;
109
-		$this->config = $config;
110
-
111
-		$this->setupListeners();
112
-	}
113
-
114
-	private function isSetupStarted(IUser $user): bool {
115
-		return in_array($user->getUID(), $this->setupUsers, true);
116
-	}
117
-
118
-	public function isSetupComplete(IUser $user): bool {
119
-		return in_array($user->getUID(), $this->setupUsersComplete, true);
120
-	}
121
-
122
-	private function setupBuiltinWrappers() {
123
-		Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
124
-			if ($storage->instanceOfStorage(Common::class)) {
125
-				$storage->setMountOptions($mount->getOptions());
126
-			}
127
-			return $storage;
128
-		});
129
-
130
-		Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
131
-			if (!$mount->getOption('enable_sharing', true)) {
132
-				return new PermissionsMask([
133
-					'storage' => $storage,
134
-					'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
135
-				]);
136
-			}
137
-			return $storage;
138
-		});
139
-
140
-		// install storage availability wrapper, before most other wrappers
141
-		Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
142
-			if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
143
-				return new Availability(['storage' => $storage]);
144
-			}
145
-			return $storage;
146
-		});
147
-
148
-		Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
149
-			if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
150
-				return new Encoding(['storage' => $storage]);
151
-			}
152
-			return $storage;
153
-		});
154
-
155
-		Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
156
-			// set up quota for home storages, even for other users
157
-			// which can happen when using sharing
158
-
159
-			/**
160
-			 * @var Storage $storage
161
-			 */
162
-			if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
163
-				if (is_object($storage->getUser())) {
164
-					$quota = OC_Util::getUserQuota($storage->getUser());
165
-					if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
166
-						return new Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']);
167
-					}
168
-				}
169
-			}
170
-
171
-			return $storage;
172
-		});
173
-
174
-		Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
175
-			/*
65
+    private bool $rootSetup = false;
66
+    private IEventLogger $eventLogger;
67
+    private MountProviderCollection $mountProviderCollection;
68
+    private IMountManager $mountManager;
69
+    private IUserManager $userManager;
70
+    // List of users for which at least one mount is setup
71
+    private array $setupUsers = [];
72
+    // List of users for which all mounts are setup
73
+    private array $setupUsersComplete = [];
74
+    /** @var array<string, string[]> */
75
+    private array $setupUserMountProviders = [];
76
+    private IEventDispatcher $eventDispatcher;
77
+    private IUserMountCache $userMountCache;
78
+    private ILockdownManager $lockdownManager;
79
+    private IUserSession $userSession;
80
+    private ICache $cache;
81
+    private LoggerInterface $logger;
82
+    private IConfig $config;
83
+    private bool $listeningForProviders;
84
+
85
+    public function __construct(
86
+        IEventLogger $eventLogger,
87
+        MountProviderCollection $mountProviderCollection,
88
+        IMountManager $mountManager,
89
+        IUserManager $userManager,
90
+        IEventDispatcher $eventDispatcher,
91
+        IUserMountCache $userMountCache,
92
+        ILockdownManager $lockdownManager,
93
+        IUserSession $userSession,
94
+        ICacheFactory $cacheFactory,
95
+        LoggerInterface $logger,
96
+        IConfig $config
97
+    ) {
98
+        $this->eventLogger = $eventLogger;
99
+        $this->mountProviderCollection = $mountProviderCollection;
100
+        $this->mountManager = $mountManager;
101
+        $this->userManager = $userManager;
102
+        $this->eventDispatcher = $eventDispatcher;
103
+        $this->userMountCache = $userMountCache;
104
+        $this->lockdownManager = $lockdownManager;
105
+        $this->logger = $logger;
106
+        $this->userSession = $userSession;
107
+        $this->cache = $cacheFactory->createDistributed('setupmanager::');
108
+        $this->listeningForProviders = false;
109
+        $this->config = $config;
110
+
111
+        $this->setupListeners();
112
+    }
113
+
114
+    private function isSetupStarted(IUser $user): bool {
115
+        return in_array($user->getUID(), $this->setupUsers, true);
116
+    }
117
+
118
+    public function isSetupComplete(IUser $user): bool {
119
+        return in_array($user->getUID(), $this->setupUsersComplete, true);
120
+    }
121
+
122
+    private function setupBuiltinWrappers() {
123
+        Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
124
+            if ($storage->instanceOfStorage(Common::class)) {
125
+                $storage->setMountOptions($mount->getOptions());
126
+            }
127
+            return $storage;
128
+        });
129
+
130
+        Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
131
+            if (!$mount->getOption('enable_sharing', true)) {
132
+                return new PermissionsMask([
133
+                    'storage' => $storage,
134
+                    'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
135
+                ]);
136
+            }
137
+            return $storage;
138
+        });
139
+
140
+        // install storage availability wrapper, before most other wrappers
141
+        Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
142
+            if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
143
+                return new Availability(['storage' => $storage]);
144
+            }
145
+            return $storage;
146
+        });
147
+
148
+        Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
149
+            if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
150
+                return new Encoding(['storage' => $storage]);
151
+            }
152
+            return $storage;
153
+        });
154
+
155
+        Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
156
+            // set up quota for home storages, even for other users
157
+            // which can happen when using sharing
158
+
159
+            /**
160
+             * @var Storage $storage
161
+             */
162
+            if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
163
+                if (is_object($storage->getUser())) {
164
+                    $quota = OC_Util::getUserQuota($storage->getUser());
165
+                    if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
166
+                        return new Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']);
167
+                    }
168
+                }
169
+            }
170
+
171
+            return $storage;
172
+        });
173
+
174
+        Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
175
+            /*
176 176
 			 * Do not allow any operations that modify the storage
177 177
 			 */
178
-			if ($mount->getOption('readonly', false)) {
179
-				return new PermissionsMask([
180
-					'storage' => $storage,
181
-					'mask' => Constants::PERMISSION_ALL & ~(
182
-							Constants::PERMISSION_UPDATE |
183
-							Constants::PERMISSION_CREATE |
184
-							Constants::PERMISSION_DELETE
185
-						),
186
-				]);
187
-			}
188
-			return $storage;
189
-		});
190
-	}
191
-
192
-	/**
193
-	 * Setup the full filesystem for the specified user
194
-	 */
195
-	public function setupForUser(IUser $user): void {
196
-		if ($this->isSetupComplete($user)) {
197
-			return;
198
-		}
199
-		$this->setupUsersComplete[] = $user->getUID();
200
-
201
-		if (!isset($this->setupUserMountProviders[$user->getUID()])) {
202
-			$this->setupUserMountProviders[$user->getUID()] = [];
203
-		}
204
-
205
-		$this->setupForUserWith($user, function () use ($user) {
206
-			$this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
207
-				IMountProvider $provider
208
-			) use ($user) {
209
-				return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
210
-			});
211
-		});
212
-		$this->afterUserFullySetup($user);
213
-	}
214
-
215
-	/**
216
-	 * part of the user setup that is run only once per user
217
-	 */
218
-	private function oneTimeUserSetup(IUser $user) {
219
-		if (in_array($user->getUID(), $this->setupUsers, true)) {
220
-			return;
221
-		}
222
-		$this->setupUsers[] = $user->getUID();
223
-		$prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
224
-
225
-		OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
226
-
227
-		Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
228
-
229
-		$userDir = '/' . $user->getUID() . '/files';
230
-
231
-		Filesystem::initInternal($userDir);
232
-
233
-		if ($this->lockdownManager->canAccessFilesystem()) {
234
-			// home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
235
-			$homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
236
-			$this->mountManager->addMount($homeMount);
237
-
238
-			if ($homeMount->getStorageRootId() === -1) {
239
-				$homeMount->getStorage()->mkdir('');
240
-				$homeMount->getStorage()->getScanner()->scan('');
241
-			}
242
-		} else {
243
-			$this->mountManager->addMount(new MountPoint(
244
-				new NullStorage([]),
245
-				'/' . $user->getUID()
246
-			));
247
-			$this->mountManager->addMount(new MountPoint(
248
-				new NullStorage([]),
249
-				'/' . $user->getUID() . '/files'
250
-			));
251
-			$this->setupUsersComplete[] = $user->getUID();
252
-		}
253
-
254
-		$this->listenForNewMountProviders();
255
-	}
256
-
257
-	/**
258
-	 * Final housekeeping after a user has been fully setup
259
-	 */
260
-	private function afterUserFullySetup(IUser $user): void {
261
-		$userRoot = '/' . $user->getUID() . '/';
262
-		$mounts = $this->mountManager->getAll();
263
-		$mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
264
-			return strpos($mount->getMountPoint(), $userRoot) === 0;
265
-		});
266
-		$this->userMountCache->registerMounts($user, $mounts);
267
-
268
-		$cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
269
-		if ($cacheDuration > 0) {
270
-			$this->cache->set($user->getUID(), true, $cacheDuration);
271
-		}
272
-	}
273
-
274
-	/**
275
-	 * @param IUser $user
276
-	 * @param IMountPoint $mounts
277
-	 * @return void
278
-	 * @throws \OCP\HintException
279
-	 * @throws \OC\ServerNotAvailableException
280
-	 */
281
-	private function setupForUserWith(IUser $user, callable $mountCallback): void {
282
-		$this->setupRoot();
283
-
284
-		if (!$this->isSetupStarted($user)) {
285
-			$this->oneTimeUserSetup($user);
286
-		}
287
-
288
-		$this->eventLogger->start('setup_fs', 'Setup filesystem');
289
-
290
-		if ($this->lockdownManager->canAccessFilesystem()) {
291
-			$mountCallback();
292
-		}
293
-		\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
294
-
295
-		$userDir = '/' . $user->getUID() . '/files';
296
-		OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
297
-
298
-		$this->eventLogger->end('setup_fs');
299
-	}
300
-
301
-	/**
302
-	 * Set up the root filesystem
303
-	 */
304
-	public function setupRoot(): void {
305
-		//setting up the filesystem twice can only lead to trouble
306
-		if ($this->rootSetup) {
307
-			return;
308
-		}
309
-		$this->rootSetup = true;
310
-
311
-		$this->eventLogger->start('setup_root_fs', 'Setup root filesystem');
312
-
313
-		// load all filesystem apps before, so no setup-hook gets lost
314
-		OC_App::loadApps(['filesystem']);
315
-		$prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
316
-
317
-		$this->setupBuiltinWrappers();
318
-
319
-		Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
320
-
321
-		$rootMounts = $this->mountProviderCollection->getRootMounts();
322
-		foreach ($rootMounts as $rootMountProvider) {
323
-			$this->mountManager->addMount($rootMountProvider);
324
-		}
325
-
326
-		$this->eventLogger->end('setup_root_fs');
327
-	}
328
-
329
-	/**
330
-	 * Get the user to setup for a path or `null` if the root needs to be setup
331
-	 *
332
-	 * @param string $path
333
-	 * @return IUser|null
334
-	 */
335
-	private function getUserForPath(string $path) {
336
-		if (substr_count($path, '/') < 2) {
337
-			if ($user = $this->userSession->getUser()) {
338
-				return $user;
339
-			} else {
340
-				return null;
341
-			}
342
-		} elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
343
-			return null;
344
-		} else {
345
-			[, $userId] = explode('/', $path);
346
-		}
347
-
348
-		return $this->userManager->get($userId);
349
-	}
350
-
351
-	/**
352
-	 * Set up the filesystem for the specified path
353
-	 */
354
-	public function setupForPath(string $path, bool $includeChildren = false): void {
355
-		$user = $this->getUserForPath($path);
356
-		if (!$user) {
357
-			$this->setupRoot();
358
-			return;
359
-		}
360
-
361
-		if ($this->isSetupComplete($user)) {
362
-			return;
363
-		}
364
-
365
-		if ($this->fullSetupRequired($user)) {
366
-			$this->setupForUser($user);
367
-			return;
368
-		}
369
-
370
-		// for the user's home folder, it's always the home mount
371
-		if (rtrim($path) === "/" . $user->getUID() . "/files" && !$includeChildren) {
372
-			$this->oneTimeUserSetup($user);
373
-			return;
374
-		}
375
-
376
-		if (!isset($this->setupUserMountProviders[$user->getUID()])) {
377
-			$this->setupUserMountProviders[$user->getUID()] = [];
378
-		}
379
-		$setupProviders = &$this->setupUserMountProviders[$user->getUID()];
380
-		$currentProviders = [];
381
-
382
-		try {
383
-			$cachedMount = $this->userMountCache->getMountForPath($user, $path);
384
-		} catch (NotFoundException $e) {
385
-			$this->setupForUser($user);
386
-			return;
387
-		}
388
-
389
-		$mounts = [];
390
-		if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
391
-			$setupProviders[] = $cachedMount->getMountProvider();
392
-			$currentProviders[] = $cachedMount->getMountProvider();
393
-			if ($cachedMount->getMountProvider()) {
394
-				$mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
395
-			} else {
396
-				$this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
397
-				$this->setupForUser($user);
398
-				return;
399
-			}
400
-		}
401
-
402
-		if ($includeChildren) {
403
-			$subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
404
-			foreach ($subCachedMounts as $cachedMount) {
405
-				if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
406
-					$setupProviders[] = $cachedMount->getMountProvider();
407
-					$currentProviders[] = $cachedMount->getMountProvider();
408
-					if ($cachedMount->getMountProvider()) {
409
-						$mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
410
-					} else {
411
-						$this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
412
-						$this->setupForUser($user);
413
-						return;
414
-					}
415
-				}
416
-			}
417
-		}
418
-
419
-		if (count($mounts)) {
420
-			$this->userMountCache->registerMounts($user, $mounts, $currentProviders);
421
-			$this->setupForUserWith($user, function () use ($mounts) {
422
-				array_walk($mounts, [$this->mountManager, 'addMount']);
423
-			});
424
-		} elseif (!$this->isSetupStarted($user)) {
425
-			$this->oneTimeUserSetup($user);
426
-		}
427
-	}
428
-
429
-	private function fullSetupRequired(IUser $user): bool {
430
-		// we perform a "cached" setup only after having done the full setup recently
431
-		// this is also used to trigger a full setup after handling events that are likely
432
-		// to change the available mounts
433
-		return !$this->cache->get($user->getUID());
434
-	}
435
-
436
-	/**
437
-	 * @param string $path
438
-	 * @param string[] $providers
439
-	 */
440
-	public function setupForProvider(string $path, array $providers): void {
441
-		$user = $this->getUserForPath($path);
442
-		if (!$user) {
443
-			$this->setupRoot();
444
-			return;
445
-		}
446
-
447
-		if ($this->isSetupComplete($user)) {
448
-			return;
449
-		}
450
-
451
-		if ($this->fullSetupRequired($user)) {
452
-			$this->setupForUser($user);
453
-			return;
454
-		}
455
-
456
-		// home providers are always used
457
-		$providers = array_filter($providers, function (string $provider) {
458
-			return !is_subclass_of($provider, IHomeMountProvider::class);
459
-		});
460
-
461
-		if (in_array('', $providers)) {
462
-			$this->setupForUser($user);
463
-		}
464
-		$setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
465
-
466
-		$providers = array_diff($providers, $setupProviders);
467
-		if (count($providers) === 0) {
468
-			if (!$this->isSetupStarted($user)) {
469
-				$this->oneTimeUserSetup($user);
470
-			}
471
-			return;
472
-		} else {
473
-			$this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
474
-			$mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
475
-		}
476
-
477
-		$this->userMountCache->registerMounts($user, $mounts, $providers);
478
-		$this->setupForUserWith($user, function () use ($mounts) {
479
-			array_walk($mounts, [$this->mountManager, 'addMount']);
480
-		});
481
-	}
482
-
483
-	public function tearDown() {
484
-		$this->setupUsers = [];
485
-		$this->setupUsersComplete = [];
486
-		$this->setupUserMountProviders = [];
487
-		$this->rootSetup = false;
488
-		$this->mountManager->clear();
489
-		$this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
490
-	}
491
-
492
-	/**
493
-	 * Get mounts from mount providers that are registered after setup
494
-	 */
495
-	private function listenForNewMountProviders() {
496
-		if (!$this->listeningForProviders) {
497
-			$this->listeningForProviders = true;
498
-			$this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
499
-				IMountProvider $provider
500
-			) {
501
-				foreach ($this->setupUsers as $userId) {
502
-					$user = $this->userManager->get($userId);
503
-					if ($user) {
504
-						$mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
505
-						array_walk($mounts, [$this->mountManager, 'addMount']);
506
-					}
507
-				}
508
-			});
509
-		}
510
-	}
511
-
512
-	private function setupListeners() {
513
-		// note that this event handling is intentionally pessimistic
514
-		// clearing the cache to often is better than not enough
515
-
516
-		$this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
517
-			$this->cache->remove($event->getUser()->getUID());
518
-		});
519
-		$this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
520
-			$this->cache->remove($event->getUser()->getUID());
521
-		});
522
-		$this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
523
-			$this->cache->remove($event->getShare()->getSharedWith());
524
-		});
525
-		$this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
526
-		) {
527
-			if ($user = $event->getUser()) {
528
-				$this->cache->remove($user->getUID());
529
-			} else {
530
-				$this->cache->clear();
531
-			}
532
-		});
533
-
534
-		$genericEvents = [
535
-			'\OCA\Circles::onCircleCreation',
536
-			'\OCA\Circles::onCircleDestruction',
537
-			'\OCA\Circles::onMemberNew',
538
-			'\OCA\Circles::onMemberLeaving',
539
-		];
540
-
541
-		foreach ($genericEvents as $genericEvent) {
542
-			$this->eventDispatcher->addListener($genericEvent, function ($event) {
543
-				$this->cache->clear();
544
-			});
545
-		}
546
-	}
178
+            if ($mount->getOption('readonly', false)) {
179
+                return new PermissionsMask([
180
+                    'storage' => $storage,
181
+                    'mask' => Constants::PERMISSION_ALL & ~(
182
+                            Constants::PERMISSION_UPDATE |
183
+                            Constants::PERMISSION_CREATE |
184
+                            Constants::PERMISSION_DELETE
185
+                        ),
186
+                ]);
187
+            }
188
+            return $storage;
189
+        });
190
+    }
191
+
192
+    /**
193
+     * Setup the full filesystem for the specified user
194
+     */
195
+    public function setupForUser(IUser $user): void {
196
+        if ($this->isSetupComplete($user)) {
197
+            return;
198
+        }
199
+        $this->setupUsersComplete[] = $user->getUID();
200
+
201
+        if (!isset($this->setupUserMountProviders[$user->getUID()])) {
202
+            $this->setupUserMountProviders[$user->getUID()] = [];
203
+        }
204
+
205
+        $this->setupForUserWith($user, function () use ($user) {
206
+            $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
207
+                IMountProvider $provider
208
+            ) use ($user) {
209
+                return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
210
+            });
211
+        });
212
+        $this->afterUserFullySetup($user);
213
+    }
214
+
215
+    /**
216
+     * part of the user setup that is run only once per user
217
+     */
218
+    private function oneTimeUserSetup(IUser $user) {
219
+        if (in_array($user->getUID(), $this->setupUsers, true)) {
220
+            return;
221
+        }
222
+        $this->setupUsers[] = $user->getUID();
223
+        $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
224
+
225
+        OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
226
+
227
+        Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
228
+
229
+        $userDir = '/' . $user->getUID() . '/files';
230
+
231
+        Filesystem::initInternal($userDir);
232
+
233
+        if ($this->lockdownManager->canAccessFilesystem()) {
234
+            // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
235
+            $homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
236
+            $this->mountManager->addMount($homeMount);
237
+
238
+            if ($homeMount->getStorageRootId() === -1) {
239
+                $homeMount->getStorage()->mkdir('');
240
+                $homeMount->getStorage()->getScanner()->scan('');
241
+            }
242
+        } else {
243
+            $this->mountManager->addMount(new MountPoint(
244
+                new NullStorage([]),
245
+                '/' . $user->getUID()
246
+            ));
247
+            $this->mountManager->addMount(new MountPoint(
248
+                new NullStorage([]),
249
+                '/' . $user->getUID() . '/files'
250
+            ));
251
+            $this->setupUsersComplete[] = $user->getUID();
252
+        }
253
+
254
+        $this->listenForNewMountProviders();
255
+    }
256
+
257
+    /**
258
+     * Final housekeeping after a user has been fully setup
259
+     */
260
+    private function afterUserFullySetup(IUser $user): void {
261
+        $userRoot = '/' . $user->getUID() . '/';
262
+        $mounts = $this->mountManager->getAll();
263
+        $mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
264
+            return strpos($mount->getMountPoint(), $userRoot) === 0;
265
+        });
266
+        $this->userMountCache->registerMounts($user, $mounts);
267
+
268
+        $cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
269
+        if ($cacheDuration > 0) {
270
+            $this->cache->set($user->getUID(), true, $cacheDuration);
271
+        }
272
+    }
273
+
274
+    /**
275
+     * @param IUser $user
276
+     * @param IMountPoint $mounts
277
+     * @return void
278
+     * @throws \OCP\HintException
279
+     * @throws \OC\ServerNotAvailableException
280
+     */
281
+    private function setupForUserWith(IUser $user, callable $mountCallback): void {
282
+        $this->setupRoot();
283
+
284
+        if (!$this->isSetupStarted($user)) {
285
+            $this->oneTimeUserSetup($user);
286
+        }
287
+
288
+        $this->eventLogger->start('setup_fs', 'Setup filesystem');
289
+
290
+        if ($this->lockdownManager->canAccessFilesystem()) {
291
+            $mountCallback();
292
+        }
293
+        \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
294
+
295
+        $userDir = '/' . $user->getUID() . '/files';
296
+        OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
297
+
298
+        $this->eventLogger->end('setup_fs');
299
+    }
300
+
301
+    /**
302
+     * Set up the root filesystem
303
+     */
304
+    public function setupRoot(): void {
305
+        //setting up the filesystem twice can only lead to trouble
306
+        if ($this->rootSetup) {
307
+            return;
308
+        }
309
+        $this->rootSetup = true;
310
+
311
+        $this->eventLogger->start('setup_root_fs', 'Setup root filesystem');
312
+
313
+        // load all filesystem apps before, so no setup-hook gets lost
314
+        OC_App::loadApps(['filesystem']);
315
+        $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
316
+
317
+        $this->setupBuiltinWrappers();
318
+
319
+        Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
320
+
321
+        $rootMounts = $this->mountProviderCollection->getRootMounts();
322
+        foreach ($rootMounts as $rootMountProvider) {
323
+            $this->mountManager->addMount($rootMountProvider);
324
+        }
325
+
326
+        $this->eventLogger->end('setup_root_fs');
327
+    }
328
+
329
+    /**
330
+     * Get the user to setup for a path or `null` if the root needs to be setup
331
+     *
332
+     * @param string $path
333
+     * @return IUser|null
334
+     */
335
+    private function getUserForPath(string $path) {
336
+        if (substr_count($path, '/') < 2) {
337
+            if ($user = $this->userSession->getUser()) {
338
+                return $user;
339
+            } else {
340
+                return null;
341
+            }
342
+        } elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
343
+            return null;
344
+        } else {
345
+            [, $userId] = explode('/', $path);
346
+        }
347
+
348
+        return $this->userManager->get($userId);
349
+    }
350
+
351
+    /**
352
+     * Set up the filesystem for the specified path
353
+     */
354
+    public function setupForPath(string $path, bool $includeChildren = false): void {
355
+        $user = $this->getUserForPath($path);
356
+        if (!$user) {
357
+            $this->setupRoot();
358
+            return;
359
+        }
360
+
361
+        if ($this->isSetupComplete($user)) {
362
+            return;
363
+        }
364
+
365
+        if ($this->fullSetupRequired($user)) {
366
+            $this->setupForUser($user);
367
+            return;
368
+        }
369
+
370
+        // for the user's home folder, it's always the home mount
371
+        if (rtrim($path) === "/" . $user->getUID() . "/files" && !$includeChildren) {
372
+            $this->oneTimeUserSetup($user);
373
+            return;
374
+        }
375
+
376
+        if (!isset($this->setupUserMountProviders[$user->getUID()])) {
377
+            $this->setupUserMountProviders[$user->getUID()] = [];
378
+        }
379
+        $setupProviders = &$this->setupUserMountProviders[$user->getUID()];
380
+        $currentProviders = [];
381
+
382
+        try {
383
+            $cachedMount = $this->userMountCache->getMountForPath($user, $path);
384
+        } catch (NotFoundException $e) {
385
+            $this->setupForUser($user);
386
+            return;
387
+        }
388
+
389
+        $mounts = [];
390
+        if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
391
+            $setupProviders[] = $cachedMount->getMountProvider();
392
+            $currentProviders[] = $cachedMount->getMountProvider();
393
+            if ($cachedMount->getMountProvider()) {
394
+                $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
395
+            } else {
396
+                $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
397
+                $this->setupForUser($user);
398
+                return;
399
+            }
400
+        }
401
+
402
+        if ($includeChildren) {
403
+            $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
404
+            foreach ($subCachedMounts as $cachedMount) {
405
+                if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
406
+                    $setupProviders[] = $cachedMount->getMountProvider();
407
+                    $currentProviders[] = $cachedMount->getMountProvider();
408
+                    if ($cachedMount->getMountProvider()) {
409
+                        $mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
410
+                    } else {
411
+                        $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
412
+                        $this->setupForUser($user);
413
+                        return;
414
+                    }
415
+                }
416
+            }
417
+        }
418
+
419
+        if (count($mounts)) {
420
+            $this->userMountCache->registerMounts($user, $mounts, $currentProviders);
421
+            $this->setupForUserWith($user, function () use ($mounts) {
422
+                array_walk($mounts, [$this->mountManager, 'addMount']);
423
+            });
424
+        } elseif (!$this->isSetupStarted($user)) {
425
+            $this->oneTimeUserSetup($user);
426
+        }
427
+    }
428
+
429
+    private function fullSetupRequired(IUser $user): bool {
430
+        // we perform a "cached" setup only after having done the full setup recently
431
+        // this is also used to trigger a full setup after handling events that are likely
432
+        // to change the available mounts
433
+        return !$this->cache->get($user->getUID());
434
+    }
435
+
436
+    /**
437
+     * @param string $path
438
+     * @param string[] $providers
439
+     */
440
+    public function setupForProvider(string $path, array $providers): void {
441
+        $user = $this->getUserForPath($path);
442
+        if (!$user) {
443
+            $this->setupRoot();
444
+            return;
445
+        }
446
+
447
+        if ($this->isSetupComplete($user)) {
448
+            return;
449
+        }
450
+
451
+        if ($this->fullSetupRequired($user)) {
452
+            $this->setupForUser($user);
453
+            return;
454
+        }
455
+
456
+        // home providers are always used
457
+        $providers = array_filter($providers, function (string $provider) {
458
+            return !is_subclass_of($provider, IHomeMountProvider::class);
459
+        });
460
+
461
+        if (in_array('', $providers)) {
462
+            $this->setupForUser($user);
463
+        }
464
+        $setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
465
+
466
+        $providers = array_diff($providers, $setupProviders);
467
+        if (count($providers) === 0) {
468
+            if (!$this->isSetupStarted($user)) {
469
+                $this->oneTimeUserSetup($user);
470
+            }
471
+            return;
472
+        } else {
473
+            $this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
474
+            $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
475
+        }
476
+
477
+        $this->userMountCache->registerMounts($user, $mounts, $providers);
478
+        $this->setupForUserWith($user, function () use ($mounts) {
479
+            array_walk($mounts, [$this->mountManager, 'addMount']);
480
+        });
481
+    }
482
+
483
+    public function tearDown() {
484
+        $this->setupUsers = [];
485
+        $this->setupUsersComplete = [];
486
+        $this->setupUserMountProviders = [];
487
+        $this->rootSetup = false;
488
+        $this->mountManager->clear();
489
+        $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
490
+    }
491
+
492
+    /**
493
+     * Get mounts from mount providers that are registered after setup
494
+     */
495
+    private function listenForNewMountProviders() {
496
+        if (!$this->listeningForProviders) {
497
+            $this->listeningForProviders = true;
498
+            $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
499
+                IMountProvider $provider
500
+            ) {
501
+                foreach ($this->setupUsers as $userId) {
502
+                    $user = $this->userManager->get($userId);
503
+                    if ($user) {
504
+                        $mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
505
+                        array_walk($mounts, [$this->mountManager, 'addMount']);
506
+                    }
507
+                }
508
+            });
509
+        }
510
+    }
511
+
512
+    private function setupListeners() {
513
+        // note that this event handling is intentionally pessimistic
514
+        // clearing the cache to often is better than not enough
515
+
516
+        $this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
517
+            $this->cache->remove($event->getUser()->getUID());
518
+        });
519
+        $this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
520
+            $this->cache->remove($event->getUser()->getUID());
521
+        });
522
+        $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
523
+            $this->cache->remove($event->getShare()->getSharedWith());
524
+        });
525
+        $this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
526
+        ) {
527
+            if ($user = $event->getUser()) {
528
+                $this->cache->remove($user->getUID());
529
+            } else {
530
+                $this->cache->clear();
531
+            }
532
+        });
533
+
534
+        $genericEvents = [
535
+            '\OCA\Circles::onCircleCreation',
536
+            '\OCA\Circles::onCircleDestruction',
537
+            '\OCA\Circles::onMemberNew',
538
+            '\OCA\Circles::onMemberLeaving',
539
+        ];
540
+
541
+        foreach ($genericEvents as $genericEvent) {
542
+            $this->eventDispatcher->addListener($genericEvent, function ($event) {
543
+                $this->cache->clear();
544
+            });
545
+        }
546
+    }
547 547
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 	}
121 121
 
122 122
 	private function setupBuiltinWrappers() {
123
-		Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
123
+		Filesystem::addStorageWrapper('mount_options', function($mountPoint, IStorage $storage, IMountPoint $mount) {
124 124
 			if ($storage->instanceOfStorage(Common::class)) {
125 125
 				$storage->setMountOptions($mount->getOptions());
126 126
 			}
127 127
 			return $storage;
128 128
 		});
129 129
 
130
-		Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
130
+		Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, IStorage $storage, IMountPoint $mount) {
131 131
 			if (!$mount->getOption('enable_sharing', true)) {
132 132
 				return new PermissionsMask([
133 133
 					'storage' => $storage,
@@ -138,21 +138,21 @@  discard block
 block discarded – undo
138 138
 		});
139 139
 
140 140
 		// install storage availability wrapper, before most other wrappers
141
-		Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
141
+		Filesystem::addStorageWrapper('oc_availability', function($mountPoint, IStorage $storage) {
142 142
 			if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
143 143
 				return new Availability(['storage' => $storage]);
144 144
 			}
145 145
 			return $storage;
146 146
 		});
147 147
 
148
-		Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
148
+		Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, IStorage $storage, IMountPoint $mount) {
149 149
 			if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
150 150
 				return new Encoding(['storage' => $storage]);
151 151
 			}
152 152
 			return $storage;
153 153
 		});
154 154
 
155
-		Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
155
+		Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) {
156 156
 			// set up quota for home storages, even for other users
157 157
 			// which can happen when using sharing
158 158
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 			return $storage;
172 172
 		});
173 173
 
174
-		Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
174
+		Filesystem::addStorageWrapper('readonly', function($mountPoint, IStorage $storage, IMountPoint $mount) {
175 175
 			/*
176 176
 			 * Do not allow any operations that modify the storage
177 177
 			 */
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 			$this->setupUserMountProviders[$user->getUID()] = [];
203 203
 		}
204 204
 
205
-		$this->setupForUserWith($user, function () use ($user) {
206
-			$this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
205
+		$this->setupForUserWith($user, function() use ($user) {
206
+			$this->mountProviderCollection->addMountForUser($user, $this->mountManager, function(
207 207
 				IMountProvider $provider
208 208
 			) use ($user) {
209 209
 				return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 		Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
228 228
 
229
-		$userDir = '/' . $user->getUID() . '/files';
229
+		$userDir = '/'.$user->getUID().'/files';
230 230
 
231 231
 		Filesystem::initInternal($userDir);
232 232
 
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
 		} else {
243 243
 			$this->mountManager->addMount(new MountPoint(
244 244
 				new NullStorage([]),
245
-				'/' . $user->getUID()
245
+				'/'.$user->getUID()
246 246
 			));
247 247
 			$this->mountManager->addMount(new MountPoint(
248 248
 				new NullStorage([]),
249
-				'/' . $user->getUID() . '/files'
249
+				'/'.$user->getUID().'/files'
250 250
 			));
251 251
 			$this->setupUsersComplete[] = $user->getUID();
252 252
 		}
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	 * Final housekeeping after a user has been fully setup
259 259
 	 */
260 260
 	private function afterUserFullySetup(IUser $user): void {
261
-		$userRoot = '/' . $user->getUID() . '/';
261
+		$userRoot = '/'.$user->getUID().'/';
262 262
 		$mounts = $this->mountManager->getAll();
263
-		$mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
263
+		$mounts = array_filter($mounts, function(IMountPoint $mount) use ($userRoot) {
264 264
 			return strpos($mount->getMountPoint(), $userRoot) === 0;
265 265
 		});
266 266
 		$this->userMountCache->registerMounts($user, $mounts);
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		}
293 293
 		\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
294 294
 
295
-		$userDir = '/' . $user->getUID() . '/files';
295
+		$userDir = '/'.$user->getUID().'/files';
296 296
 		OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
297 297
 
298 298
 		$this->eventLogger->end('setup_fs');
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 			} else {
340 340
 				return null;
341 341
 			}
342
-		} elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
342
+		} elseif (strpos($path, '/appdata_'.\OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
343 343
 			return null;
344 344
 		} else {
345 345
 			[, $userId] = explode('/', $path);
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 		}
369 369
 
370 370
 		// for the user's home folder, it's always the home mount
371
-		if (rtrim($path) === "/" . $user->getUID() . "/files" && !$includeChildren) {
371
+		if (rtrim($path) === "/".$user->getUID()."/files" && !$includeChildren) {
372 372
 			$this->oneTimeUserSetup($user);
373 373
 			return;
374 374
 		}
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 			if ($cachedMount->getMountProvider()) {
394 394
 				$mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
395 395
 			} else {
396
-				$this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
396
+				$this->logger->debug("mount at ".$cachedMount->getMountPoint()." has no provider set, performing full setup");
397 397
 				$this->setupForUser($user);
398 398
 				return;
399 399
 			}
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 					if ($cachedMount->getMountProvider()) {
409 409
 						$mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
410 410
 					} else {
411
-						$this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
411
+						$this->logger->debug("mount at ".$cachedMount->getMountPoint()." has no provider set, performing full setup");
412 412
 						$this->setupForUser($user);
413 413
 						return;
414 414
 					}
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 
419 419
 		if (count($mounts)) {
420 420
 			$this->userMountCache->registerMounts($user, $mounts, $currentProviders);
421
-			$this->setupForUserWith($user, function () use ($mounts) {
421
+			$this->setupForUserWith($user, function() use ($mounts) {
422 422
 				array_walk($mounts, [$this->mountManager, 'addMount']);
423 423
 			});
424 424
 		} elseif (!$this->isSetupStarted($user)) {
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 		}
455 455
 
456 456
 		// home providers are always used
457
-		$providers = array_filter($providers, function (string $provider) {
457
+		$providers = array_filter($providers, function(string $provider) {
458 458
 			return !is_subclass_of($provider, IHomeMountProvider::class);
459 459
 		});
460 460
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 		}
476 476
 
477 477
 		$this->userMountCache->registerMounts($user, $mounts, $providers);
478
-		$this->setupForUserWith($user, function () use ($mounts) {
478
+		$this->setupForUserWith($user, function() use ($mounts) {
479 479
 			array_walk($mounts, [$this->mountManager, 'addMount']);
480 480
 		});
481 481
 	}
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 	private function listenForNewMountProviders() {
496 496
 		if (!$this->listeningForProviders) {
497 497
 			$this->listeningForProviders = true;
498
-			$this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
498
+			$this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function(
499 499
 				IMountProvider $provider
500 500
 			) {
501 501
 				foreach ($this->setupUsers as $userId) {
@@ -513,16 +513,16 @@  discard block
 block discarded – undo
513 513
 		// note that this event handling is intentionally pessimistic
514 514
 		// clearing the cache to often is better than not enough
515 515
 
516
-		$this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
516
+		$this->eventDispatcher->addListener(UserAddedEvent::class, function(UserAddedEvent $event) {
517 517
 			$this->cache->remove($event->getUser()->getUID());
518 518
 		});
519
-		$this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
519
+		$this->eventDispatcher->addListener(UserRemovedEvent::class, function(UserRemovedEvent $event) {
520 520
 			$this->cache->remove($event->getUser()->getUID());
521 521
 		});
522
-		$this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
522
+		$this->eventDispatcher->addListener(ShareCreatedEvent::class, function(ShareCreatedEvent $event) {
523 523
 			$this->cache->remove($event->getShare()->getSharedWith());
524 524
 		});
525
-		$this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
525
+		$this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function(InvalidateMountCacheEvent $event
526 526
 		) {
527 527
 			if ($user = $event->getUser()) {
528 528
 				$this->cache->remove($user->getUID());
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 		];
540 540
 
541 541
 		foreach ($genericEvents as $genericEvent) {
542
-			$this->eventDispatcher->addListener($genericEvent, function ($event) {
542
+			$this->eventDispatcher->addListener($genericEvent, function($event) {
543 543
 				$this->cache->clear();
544 544
 			});
545 545
 		}
Please login to merge, or discard this patch.