Skip to content
Open
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
23 changes: 16 additions & 7 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class Manager implements IMountManager {
/** @var array<string, IMountPoint> */
private array $mounts = [];
private array $mountsByProvider = [];
private bool $areMountsSorted = false;
/** @var list<string>|null $mountKeys */
private ?array $mountKeys = null;
Expand All @@ -36,7 +37,11 @@ public function __construct(SetupManagerFactory $setupManagerFactory) {
}

public function addMount(IMountPoint $mount): void {
$this->mounts[$mount->getMountPoint()] = $mount;
$mountPoint = $mount->getMountPoint();
$mountProvider = $mount->getMountProvider();
$this->mounts[$mountPoint] = $mount;
$this->mountsByProvider[$mountProvider] ??= [];
$this->mountsByProvider[$mountProvider][$mountPoint] = $mount;
$this->pathCache->clear();
$this->inPathCache->clear();
$this->areMountsSorted = false;
Expand Down Expand Up @@ -167,6 +172,7 @@ private function binarySearch(array $sortedArray, array $sortedKeys, string $pre

public function clear(): void {
$this->mounts = [];
$this->mountsByProvider = [];
$this->pathCache->clear();
$this->inPathCache->clear();
}
Expand Down Expand Up @@ -236,15 +242,18 @@ public function getSetupManager(): SetupManager {
* @param string[] $mountProviders
* @return array<string, IMountPoint>
*/
public function getMountsByMountProvider(string $path, array $mountProviders) {
public function getMountsByMountProvider(string $path, array $mountProviders): array {
$this->getSetupManager()->setupForProvider($path, $mountProviders);
if (in_array('', $mountProviders)) {
if (\in_array('', $mountProviders)) {
return $this->mounts;
} else {
return array_filter($this->mounts, function ($mount) use ($mountProviders) {
return in_array($mount->getMountProvider(), $mountProviders);
});
}

$mounts = [];
foreach ($mountProviders as $mountProvider) {
$mounts[] = $this->mountsByProvider[$mountProvider];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$mounts[] = $this->mountsByProvider[$mountProvider];
$mounts[] = $this->mountsByProvider[$mountProvider] ?? [];

Maybe just in case the provider has no mounts? Not sure if that could happen here, so your judgement.

}

return array_merge(...$mounts);
}

/**
Expand Down
Loading