Skip to content

Commit ed6d0e5

Browse files
authored
Merge pull request #57286 from nextcloud/fix/54562/add-forchildren-to-setupforpath
fix: add $forChildren parameter to IPartialMountProvider
2 parents c614a13 + 6e9ba89 commit ed6d0e5

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

lib/private/Files/Config/MountProviderCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function getMountsForUser(IUser $user): array {
9191
public function getUserMountsFromProviderByPath(
9292
string $providerClass,
9393
string $path,
94+
bool $forChildren,
9495
array $mountProviderArgs,
9596
): array {
9697
$provider = $this->providers[$providerClass] ?? null;
@@ -107,6 +108,7 @@ public function getUserMountsFromProviderByPath(
107108
/** @var IPartialMountProvider $provider */
108109
return $provider->getMountsForPath(
109110
$path,
111+
$forChildren,
110112
$mountProviderArgs,
111113
$this->loader,
112114
);

lib/private/Files/SetupManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ public function setupForPath(string $path, bool $includeChildren = false): void
486486
$this->mountProviderCollection->getUserMountsFromProviderByPath(
487487
$mountProvider,
488488
$path,
489+
false,
489490
[$providerArgs]
490491
)
491492
);
@@ -573,6 +574,7 @@ static function (ICachedMountInfo $info) use ($rootsMetadata) {
573574
= $this->mountProviderCollection->getUserMountsFromProviderByPath(
574575
$providerClass,
575576
$path,
577+
true,
576578
$providerArgs,
577579
);
578580
}

lib/public/Files/Config/IPartialMountProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ interface IPartialMountProvider extends IMountProvider {
3030
* corresponding IMountPoint instances.
3131
*
3232
* @param string $path path for which the mounts are set up
33+
* @param bool $forChildren when true, only child mounts for path should be returned
3334
* @param IMountProviderArgs[] $mountProviderArgs
3435
* @param IStorageFactory $loader
3536
* @return array<string, IMountPoint> IMountPoint instances, indexed by
3637
* mount-point
3738
*/
3839
public function getMountsForPath(
3940
string $path,
41+
bool $forChildren,
4042
array $mountProviderArgs,
4143
IStorageFactory $loader,
4244
): array;

tests/lib/Files/SetupManagerTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public function testTearDown(): void {
118118
$this->setupManager->tearDown();
119119
}
120120

121+
/**
122+
* Tests that a path is not set up twice for providers implementing
123+
* IPartialMountProvider in setupForPath.
124+
*/
121125
public function testSetupForPathWithPartialProviderSkipsAlreadySetupPath(): void {
122126
$cachedMount = $this->getCachedMountInfo($this->mountPoint, 42);
123127

@@ -140,6 +144,7 @@ public function testSetupForPathWithPartialProviderSkipsAlreadySetupPath(): void
140144
->with(
141145
SetupManagerTestPartialMountProvider::class,
142146
$this->path,
147+
false,
143148
$this->callback(function (array $args) use ($cachedMount) {
144149
$this->assertCount(1, $args);
145150
$this->assertInstanceOf(IMountProviderArgs::class, $args[0]);
@@ -172,6 +177,10 @@ public function testSetupForPathWithPartialProviderSkipsAlreadySetupPath(): void
172177
$this->setupManager->setupForPath($this->path, false);
173178
}
174179

180+
/**
181+
* Tests that providers that are not implementing IPartialMountProvider are
182+
* not set up more than once by setupForPath.
183+
*/
175184
public function testSetupForPathWithNonPartialProviderSkipsAlreadySetupProvider(): void {
176185
$cachedMount = $this->getCachedMountInfo($this->mountPoint, 42,
177186
IMountProvider::class);
@@ -211,6 +220,11 @@ public function testSetupForPathWithNonPartialProviderSkipsAlreadySetupProvider(
211220
$this->setupManager->setupForPath($this->path, false);
212221
}
213222

223+
/**
224+
* Tests that setupForPath does not instantiate already set up providers
225+
* when called for the same path first with $withChildren set to true
226+
* and then set to false.
227+
*/
214228
public function testSetupForPathWithChildrenAndNonPartialProviderSkipsAlreadySetupProvider(): void {
215229
$cachedMount = $this->getCachedMountInfo($this->mountPoint, 42, IMountProvider::class);
216230
$additionalCachedMount = $this->getCachedMountInfo($this->mountPoint . 'additional/', 43, SetupManagerTestFullMountProvider::class);
@@ -269,6 +283,10 @@ public function testSetupForPathWithChildrenAndNonPartialProviderSkipsAlreadySet
269283
$this->setupManager->setupForPath($this->path, false);
270284
}
271285

286+
/**
287+
* Tests that setupForPath does not set up child mounts again if a parent
288+
* was set up with $withChildren set to true.
289+
*/
272290
public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlreadySetup(): void {
273291
$childPath = "{$this->path}/child";
274292
$childMountPoint = "{$childPath}/";
@@ -322,6 +340,7 @@ public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlrea
322340
->willReturnCallback(function (
323341
string $providerClass,
324342
string $pathArg,
343+
bool $forChildren,
325344
array $mountProviderArgs,
326345
) use (
327346
$cachedChildMount,
@@ -335,14 +354,17 @@ public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlrea
335354
// call for the parent
336355
$expectedCachedMount = $cachedMount;
337356
$mountPoints = [$partialMount];
357+
$expectedForChildren = false;
338358
} else {
339359
// call for the children
340360
$expectedCachedMount = $cachedChildMount;
341361
$mountPoints = [$partialChildMount];
362+
$expectedForChildren = true;
342363
}
343364

344365
$this->assertSame(SetupManagerTestPartialMountProvider::class, $providerClass);
345366
$this->assertSame($expectedPath, $pathArg);
367+
$this->assertSame($expectedForChildren, $forChildren);
346368
$this->assertCount(1, $mountProviderArgs);
347369
$this->assertInstanceOf(IMountProviderArgs::class, $mountProviderArgs[0]);
348370
$this->assertSame($expectedCachedMount, $mountProviderArgs[0]->mountInfo);
@@ -376,6 +398,10 @@ public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlrea
376398
$this->setupManager->setupForPath($childPath, true);
377399
}
378400

401+
/**
402+
* Tests that when called twice setupForPath does not set up mounts from
403+
* providers implementing IPartialMountProviders or IMountProvider.
404+
*/
379405
public function testSetupForPathHandlesPartialAndFullProvidersWithChildren(): void {
380406
$parentPartialCachedMount = $this->getCachedMountInfo($this->mountPoint, 42);
381407
$childCachedPartialMount = $this->getCachedMountInfo("{$this->mountPoint}partial/", 43);
@@ -419,7 +445,7 @@ public function testSetupForPathHandlesPartialAndFullProvidersWithChildren(): vo
419445
$invokedCount = $this->exactly(2);
420446
$this->mountProviderCollection->expects($invokedCount)
421447
->method('getUserMountsFromProviderByPath')
422-
->willReturnCallback(function (string $providerClass, string $pathArg, array $mountProviderArgs) use (
448+
->willReturnCallback(function (string $providerClass, string $pathArg, bool $forChildren, array $mountProviderArgs) use (
423449
$childCachedPartialMount,
424450
$childPartialMount,
425451
$parentPartialMount,
@@ -430,14 +456,17 @@ public function testSetupForPathHandlesPartialAndFullProvidersWithChildren(): vo
430456
// call for the parent
431457
$expectedCachedMount = $parentPartialCachedMount;
432458
$mountPoints = [$parentPartialMount];
459+
$expectedForChildren = false;
433460
} else {
434461
// call for the children
435462
$expectedCachedMount = $childCachedPartialMount;
436463
$mountPoints = [$childPartialMount];
464+
$expectedForChildren = true;
437465
}
438466

439467
$this->assertSame(SetupManagerTestPartialMountProvider::class, $providerClass);
440468
$this->assertSame($expectedPath, $pathArg);
469+
$this->assertSame($expectedForChildren, $forChildren);
441470
$this->assertCount(1, $mountProviderArgs);
442471
$this->assertInstanceOf(IMountProviderArgs::class, $mountProviderArgs[0]);
443472
$this->assertSame($expectedCachedMount, $mountProviderArgs[0]->mountInfo);
@@ -488,7 +517,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
488517
return [];
489518
}
490519

491-
public function getMountsForPath(string $path, array $mountProviderArgs, IStorageFactory $loader): array {
520+
public function getMountsForPath(string $path, bool $forChildren, array $mountProviderArgs, IStorageFactory $loader): array {
492521
return [];
493522
}
494523
}

0 commit comments

Comments
 (0)