Skip to content

Commit ecfa58d

Browse files
committed
fix(SetupManager): Include home and root providers when registering mounts
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent cc22d74 commit ecfa58d

File tree

2 files changed

+68
-57
lines changed

2 files changed

+68
-57
lines changed

lib/private/Files/Config/MountProviderCollection.php

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,60 +24,43 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
2424
use EmitterTrait;
2525

2626
/**
27-
* @var \OCP\Files\Config\IHomeMountProvider[]
27+
* @var list<IHomeMountProvider>
2828
*/
29-
private $homeProviders = [];
29+
private array $homeProviders = [];
3030

3131
/**
32-
* @var \OCP\Files\Config\IMountProvider[]
32+
* @var list<IMountProvider>
3333
*/
34-
private $providers = [];
34+
private array $providers = [];
3535

36-
/** @var \OCP\Files\Config\IRootMountProvider[] */
37-
private $rootProviders = [];
36+
/** @var list<IRootMountProvider> */
37+
private array $rootProviders = [];
3838

39-
/**
40-
* @var \OCP\Files\Storage\IStorageFactory
41-
*/
42-
private $loader;
43-
44-
/**
45-
* @var \OCP\Files\Config\IUserMountCache
46-
*/
47-
private $mountCache;
48-
49-
/** @var callable[] */
50-
private $mountFilters = [];
39+
/** @var list<callable> */
40+
private array $mountFilters = [];
5141

52-
private IEventLogger $eventLogger;
53-
54-
/**
55-
* @param \OCP\Files\Storage\IStorageFactory $loader
56-
* @param IUserMountCache $mountCache
57-
*/
5842
public function __construct(
59-
IStorageFactory $loader,
60-
IUserMountCache $mountCache,
61-
IEventLogger $eventLogger,
43+
private IStorageFactory $loader,
44+
private IUserMountCache $mountCache,
45+
private IEventLogger $eventLogger,
6246
) {
63-
$this->loader = $loader;
64-
$this->mountCache = $mountCache;
65-
$this->eventLogger = $eventLogger;
6647
}
6748

49+
/**
50+
* @return list<IMountPoint>
51+
*/
6852
private function getMountsFromProvider(IMountProvider $provider, IUser $user, IStorageFactory $loader): array {
6953
$class = str_replace('\\', '_', get_class($provider));
7054
$uid = $user->getUID();
7155
$this->eventLogger->start('fs:setup:provider:' . $class, "Getting mounts from $class for $uid");
7256
$mounts = $provider->getMountsForUser($user, $loader) ?? [];
7357
$this->eventLogger->end('fs:setup:provider:' . $class);
74-
return $mounts;
58+
return array_values($mounts);
7559
}
7660

7761
/**
78-
* @param IUser $user
79-
* @param IMountProvider[] $providers
80-
* @return IMountPoint[]
62+
* @param list<IMountProvider> $providers
63+
* @return list<IMountPoint>
8164
*/
8265
private function getUserMountsForProviders(IUser $user, array $providers): array {
8366
$loader = $this->loader;
@@ -90,10 +73,16 @@ private function getUserMountsForProviders(IUser $user, array $providers): array
9073
return $this->filterMounts($user, $mounts);
9174
}
9275

76+
/**
77+
* @return list<IMountPoint>
78+
*/
9379
public function getMountsForUser(IUser $user): array {
9480
return $this->getUserMountsForProviders($user, $this->providers);
9581
}
9682

83+
/**
84+
* @return list<IMountPoint>
85+
*/
9786
public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array {
9887
$providers = array_filter(
9988
$this->providers,
@@ -102,7 +91,10 @@ public function getUserMountsForProviderClasses(IUser $user, array $mountProvide
10291
return $this->getUserMountsForProviders($user, $providers);
10392
}
10493

105-
public function addMountForUser(IUser $user, IMountManager $mountManager, ?callable $providerFilter = null) {
94+
/**
95+
* @return list<IMountPoint>
96+
*/
97+
public function addMountForUser(IUser $user, IMountManager $mountManager, ?callable $providerFilter = null): array {
10698
// shared mount provider gets to go last since it needs to know existing files
10799
// to check for name collisions
108100
$firstMounts = [];
@@ -135,18 +127,15 @@ public function addMountForUser(IUser $user, IMountManager $mountManager, ?calla
135127
array_walk($lateMounts, [$mountManager, 'addMount']);
136128
$this->eventLogger->end('fs:setup:add-mounts');
137129

138-
return array_merge($lateMounts, $firstMounts);
130+
return array_values(array_merge($lateMounts, $firstMounts));
139131
}
140132

141133
/**
142134
* Get the configured home mount for this user
143135
*
144-
* @param \OCP\IUser $user
145-
* @return \OCP\Files\Mount\IMountPoint
146136
* @since 9.1.0
147137
*/
148-
public function getHomeMountForUser(IUser $user) {
149-
/** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
138+
public function getHomeMountForUser(IUser $user): IMountPoint {
150139
$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
151140
foreach ($providers as $homeProvider) {
152141
if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
@@ -159,34 +148,36 @@ public function getHomeMountForUser(IUser $user) {
159148

160149
/**
161150
* Add a provider for mount points
162-
*
163-
* @param \OCP\Files\Config\IMountProvider $provider
164151
*/
165-
public function registerProvider(IMountProvider $provider) {
152+
public function registerProvider(IMountProvider $provider): void {
166153
$this->providers[] = $provider;
167154

168155
$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
169156
}
170157

171-
public function registerMountFilter(callable $filter) {
158+
public function registerMountFilter(callable $filter): void {
172159
$this->mountFilters[] = $filter;
173160
}
174161

175-
private function filterMounts(IUser $user, array $mountPoints) {
176-
return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
162+
/**
163+
* @param list<IMountPoint> $mountPoints
164+
* @return list<IMountPoint>
165+
*/
166+
private function filterMounts(IUser $user, array $mountPoints): array {
167+
return array_values(array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
177168
foreach ($this->mountFilters as $filter) {
178169
if ($filter($mountPoint, $user) === false) {
179170
return false;
180171
}
181172
}
182173
return true;
183-
});
174+
}));
184175
}
185176

186177
/**
187178
* Add a provider for home mount points
188179
*
189-
* @param \OCP\Files\Config\IHomeMountProvider $provider
180+
* @param IHomeMountProvider $provider
190181
* @since 9.1.0
191182
*/
192183
public function registerHomeProvider(IHomeMountProvider $provider) {
@@ -196,21 +187,19 @@ public function registerHomeProvider(IHomeMountProvider $provider) {
196187

197188
/**
198189
* Get the mount cache which can be used to search for mounts without setting up the filesystem
199-
*
200-
* @return IUserMountCache
201190
*/
202-
public function getMountCache() {
191+
public function getMountCache(): IUserMountCache {
203192
return $this->mountCache;
204193
}
205194

206-
public function registerRootProvider(IRootMountProvider $provider) {
195+
public function registerRootProvider(IRootMountProvider $provider): void {
207196
$this->rootProviders[] = $provider;
208197
}
209198

210199
/**
211200
* Get all root mountpoints
212201
*
213-
* @return \OCP\Files\Mount\IMountPoint[]
202+
* @return list<IMountPoint>
214203
* @since 20.0.0
215204
*/
216205
public function getRootMounts(): array {
@@ -226,16 +215,33 @@ public function getRootMounts(): array {
226215
throw new \Exception('No root mounts provided by any provider');
227216
}
228217

229-
return $mounts;
218+
return array_values($mounts);
230219
}
231220

232-
public function clearProviders() {
221+
public function clearProviders(): void {
233222
$this->providers = [];
234223
$this->homeProviders = [];
235224
$this->rootProviders = [];
236225
}
237226

227+
/**
228+
* @return list<IMountProvider>
229+
*/
238230
public function getProviders(): array {
239231
return $this->providers;
240232
}
233+
234+
/**
235+
* @return list<IHomeMountProvider>
236+
*/
237+
public function getHomeProviders(): array {
238+
return $this->homeProviders;
239+
}
240+
241+
/**
242+
* @return list<IRootMountProvider>
243+
*/
244+
public function getRootProviders(): array {
245+
return $this->rootProviders;
246+
}
241247
}

lib/private/Files/SetupManager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCP\Files\Config\ICachedMountInfo;
3535
use OCP\Files\Config\IHomeMountProvider;
3636
use OCP\Files\Config\IMountProvider;
37+
use OCP\Files\Config\IRootMountProvider;
3738
use OCP\Files\Config\IUserMountCache;
3839
use OCP\Files\Events\BeforeFileSystemSetupEvent;
3940
use OCP\Files\Events\InvalidateMountCacheEvent;
@@ -280,9 +281,13 @@ private function afterUserFullySetup(IUser $user, array $previouslySetupProvider
280281
$mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
281282
return str_starts_with($mount->getMountPoint(), $userRoot);
282283
});
283-
$allProviders = array_map(function (IMountProvider $provider) {
284+
$allProviders = array_map(function (IMountProvider|IHomeMountProvider|IRootMountProvider $provider) {
284285
return get_class($provider);
285-
}, $this->mountProviderCollection->getProviders());
286+
}, array_merge(
287+
$this->mountProviderCollection->getProviders(),
288+
$this->mountProviderCollection->getHomeProviders(),
289+
$this->mountProviderCollection->getRootProviders(),
290+
));
286291
$newProviders = array_diff($allProviders, $previouslySetupProviders);
287292
$mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
288293
return !in_array($mount->getMountProvider(), $previouslySetupProviders);

0 commit comments

Comments
 (0)