Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/private/Files/Config/MountProviderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function getMountsForUser(IUser $user): array {
public function getUserMountsFromProviderByPath(
string $providerClass,
string $path,
bool $forChildren,
array $mountProviderArgs,
): array {
$provider = $this->providers[$providerClass] ?? null;
Expand All @@ -107,6 +108,7 @@ public function getUserMountsFromProviderByPath(
/** @var IPartialMountProvider $provider */
return $provider->getMountsForPath(
$path,
$forChildren,
$mountProviderArgs,
$this->loader,
);
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Files/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public function setupForPath(string $path, bool $includeChildren = false): void
$this->mountProviderCollection->getUserMountsFromProviderByPath(
$mountProvider,
$path,
false,
[$providerArgs]
)
);
Expand Down Expand Up @@ -573,6 +574,7 @@ static function (ICachedMountInfo $info) use ($rootsMetadata) {
= $this->mountProviderCollection->getUserMountsFromProviderByPath(
$providerClass,
$path,
true,
$providerArgs,
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/public/Files/Config/IPartialMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ interface IPartialMountProvider extends IMountProvider {
* corresponding IMountPoint instances.
*
* @param string $path path for which the mounts are set up
* @param bool $forChildren when true, only child mounts for path should be returned
* @param IMountProviderArgs[] $mountProviderArgs
* @param IStorageFactory $loader
* @return array<string, IMountPoint> IMountPoint instances, indexed by
* mount-point
*/
public function getMountsForPath(
string $path,
bool $forChildren,
array $mountProviderArgs,
IStorageFactory $loader,
): array;
Expand Down
33 changes: 31 additions & 2 deletions tests/lib/Files/SetupManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function testTearDown(): void {
$this->setupManager->tearDown();
}

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

Expand All @@ -140,6 +144,7 @@ public function testSetupForPathWithPartialProviderSkipsAlreadySetupPath(): void
->with(
SetupManagerTestPartialMountProvider::class,
$this->path,
false,
$this->callback(function (array $args) use ($cachedMount) {
$this->assertCount(1, $args);
$this->assertInstanceOf(IMountProviderArgs::class, $args[0]);
Expand Down Expand Up @@ -172,6 +177,10 @@ public function testSetupForPathWithPartialProviderSkipsAlreadySetupPath(): void
$this->setupManager->setupForPath($this->path, false);
}

/**
* Tests that providers that are not implementing IPartialMountProvider are
* not set up more than once by setupForPath.
*/
public function testSetupForPathWithNonPartialProviderSkipsAlreadySetupProvider(): void {
$cachedMount = $this->getCachedMountInfo($this->mountPoint, 42,
IMountProvider::class);
Expand Down Expand Up @@ -211,6 +220,11 @@ public function testSetupForPathWithNonPartialProviderSkipsAlreadySetupProvider(
$this->setupManager->setupForPath($this->path, false);
}

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

/**
* Tests that setupForPath does not set up child mounts again if a parent
* was set up with $withChildren set to true.
*/
public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlreadySetup(): void {
$childPath = "{$this->path}/child";
$childMountPoint = "{$childPath}/";
Expand Down Expand Up @@ -322,6 +340,7 @@ public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlrea
->willReturnCallback(function (
string $providerClass,
string $pathArg,
bool $forChildren,
array $mountProviderArgs,
) use (
$cachedChildMount,
Expand All @@ -335,14 +354,17 @@ public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlrea
// call for the parent
$expectedCachedMount = $cachedMount;
$mountPoints = [$partialMount];
$expectedForChildren = false;
} else {
// call for the children
$expectedCachedMount = $cachedChildMount;
$mountPoints = [$partialChildMount];
$expectedForChildren = true;
}

$this->assertSame(SetupManagerTestPartialMountProvider::class, $providerClass);
$this->assertSame($expectedPath, $pathArg);
$this->assertSame($expectedForChildren, $forChildren);
$this->assertCount(1, $mountProviderArgs);
$this->assertInstanceOf(IMountProviderArgs::class, $mountProviderArgs[0]);
$this->assertSame($expectedCachedMount, $mountProviderArgs[0]->mountInfo);
Expand Down Expand Up @@ -376,6 +398,10 @@ public function testSetupForPathWithChildrenAndPartialProviderSkipsIfParentAlrea
$this->setupManager->setupForPath($childPath, true);
}

/**
* Tests that when called twice setupForPath does not set up mounts from
* providers implementing IPartialMountProviders or IMountProvider.
*/
public function testSetupForPathHandlesPartialAndFullProvidersWithChildren(): void {
$parentPartialCachedMount = $this->getCachedMountInfo($this->mountPoint, 42);
$childCachedPartialMount = $this->getCachedMountInfo("{$this->mountPoint}partial/", 43);
Expand Down Expand Up @@ -419,7 +445,7 @@ public function testSetupForPathHandlesPartialAndFullProvidersWithChildren(): vo
$invokedCount = $this->exactly(2);
$this->mountProviderCollection->expects($invokedCount)
->method('getUserMountsFromProviderByPath')
->willReturnCallback(function (string $providerClass, string $pathArg, array $mountProviderArgs) use (
->willReturnCallback(function (string $providerClass, string $pathArg, bool $forChildren, array $mountProviderArgs) use (
$childCachedPartialMount,
$childPartialMount,
$parentPartialMount,
Expand All @@ -430,14 +456,17 @@ public function testSetupForPathHandlesPartialAndFullProvidersWithChildren(): vo
// call for the parent
$expectedCachedMount = $parentPartialCachedMount;
$mountPoints = [$parentPartialMount];
$expectedForChildren = false;
} else {
// call for the children
$expectedCachedMount = $childCachedPartialMount;
$mountPoints = [$childPartialMount];
$expectedForChildren = true;
}

$this->assertSame(SetupManagerTestPartialMountProvider::class, $providerClass);
$this->assertSame($expectedPath, $pathArg);
$this->assertSame($expectedForChildren, $forChildren);
$this->assertCount(1, $mountProviderArgs);
$this->assertInstanceOf(IMountProviderArgs::class, $mountProviderArgs[0]);
$this->assertSame($expectedCachedMount, $mountProviderArgs[0]->mountInfo);
Expand Down Expand Up @@ -488,7 +517,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
return [];
}

public function getMountsForPath(string $path, array $mountProviderArgs, IStorageFactory $loader): array {
public function getMountsForPath(string $path, bool $forChildren, array $mountProviderArgs, IStorageFactory $loader): array {
return [];
}
}
Expand Down
Loading