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
6 changes: 0 additions & 6 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3641,12 +3641,6 @@
<InvalidOperand>
<code><![CDATA[$user]]></code>
</InvalidOperand>
<RedundantCondition>
<code><![CDATA[get_class($provider) !== 'OCA\Files_Sharing\MountProvider']]></code>
</RedundantCondition>
<TypeDoesNotContainType>
<code><![CDATA[get_class($provider) === 'OCA\Files_Sharing\MountProvider']]></code>
</TypeDoesNotContainType>
</file>
<file src="lib/private/Files/Config/UserMountCache.php">
<InvalidReturnType>
Expand Down
3 changes: 3 additions & 0 deletions build/stubs/php-polyfill.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
// PHP 8.4
function array_find(array $array, callable $callback) {}

// PHP 8.5
function array_any(array $array, callable $callback): bool {}

2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@
'OCP\\Files\\Config\\ICachedMountInfo' => $baseDir . '/lib/public/Files/Config/ICachedMountInfo.php',
'OCP\\Files\\Config\\IHomeMountProvider' => $baseDir . '/lib/public/Files/Config/IHomeMountProvider.php',
'OCP\\Files\\Config\\IMountProvider' => $baseDir . '/lib/public/Files/Config/IMountProvider.php',
'OCP\\Files\\Config\\IMountProviderArgs' => $baseDir . '/lib/public/Files/Config/IMountProviderArgs.php',
'OCP\\Files\\Config\\IMountProviderCollection' => $baseDir . '/lib/public/Files/Config/IMountProviderCollection.php',
'OCP\\Files\\Config\\IPartialMountProvider' => $baseDir . '/lib/public/Files/Config/IPartialMountProvider.php',
'OCP\\Files\\Config\\IRootMountProvider' => $baseDir . '/lib/public/Files/Config/IRootMountProvider.php',
'OCP\\Files\\Config\\IUserMountCache' => $baseDir . '/lib/public/Files/Config/IUserMountCache.php',
'OCP\\Files\\ConnectionLostException' => $baseDir . '/lib/public/Files/ConnectionLostException.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Files\\Config\\ICachedMountInfo' => __DIR__ . '/../../..' . '/lib/public/Files/Config/ICachedMountInfo.php',
'OCP\\Files\\Config\\IHomeMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IHomeMountProvider.php',
'OCP\\Files\\Config\\IMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IMountProvider.php',
'OCP\\Files\\Config\\IMountProviderArgs' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IMountProviderArgs.php',
'OCP\\Files\\Config\\IMountProviderCollection' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IMountProviderCollection.php',
'OCP\\Files\\Config\\IPartialMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IPartialMountProvider.php',
'OCP\\Files\\Config\\IRootMountProvider' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IRootMountProvider.php',
'OCP\\Files\\Config\\IUserMountCache' => __DIR__ . '/../../..' . '/lib/public/Files/Config/IUserMountCache.php',
'OCP\\Files\\ConnectionLostException' => __DIR__ . '/../../..' . '/lib/public/Files/ConnectionLostException.php',
Expand Down
75 changes: 59 additions & 16 deletions lib/private/Files/Config/MountProviderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@

use OC\Hooks\Emitter;
use OC\Hooks\EmitterTrait;
use OCA\Files_Sharing\MountProvider;
use OCP\Diagnostics\IEventLogger;
use OCP\Files\Config\IHomeMountProvider;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Config\IMountProviderArgs;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IPartialMountProvider;
use OCP\Files\Config\IRootMountProvider;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
use function get_class;
use function in_array;

class MountProviderCollection implements IMountProviderCollection, Emitter {
use EmitterTrait;
Expand All @@ -29,7 +34,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
private array $homeProviders = [];

/**
* @var list<IMountProvider>
* @var array<class-string<IMountProvider>, IMountProvider>
*/
private array $providers = [];

Expand Down Expand Up @@ -67,28 +72,61 @@ private function getUserMountsForProviders(IUser $user, array $providers): array
$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
return $this->getMountsFromProvider($provider, $user, $loader);
}, $providers);
$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
return array_merge($mounts, $providerMounts);
}, []);
$mounts = array_merge(...$mounts);
return $this->filterMounts($user, $mounts);
}

/**
* @return list<IMountPoint>
*/
public function getMountsForUser(IUser $user): array {
return $this->getUserMountsForProviders($user, $this->providers);
return $this->getUserMountsForProviders($user, array_values($this->providers));
}

/**
* @param IMountProviderArgs[] $mountProviderArgs
* @return array<string, IMountPoint> IMountPoint array indexed by mount
* point.
*/
public function getUserMountsFromProviderByPath(
string $providerClass,
string $path,
array $mountProviderArgs,
): array {
$provider = $this->providers[$providerClass] ?? null;
if ($provider === null) {
return [];
}

if (!is_a($providerClass, IPartialMountProvider::class, true)) {
throw new \LogicException(
'Mount provider does not support partial mounts'
);
}

/** @var IPartialMountProvider $provider */
return $provider->getMountsForPath(
$path,
$mountProviderArgs,
$this->loader,
);
}

/**
* Returns the mounts for the user from the specified provider classes.
* Providers not registered in the MountProviderCollection will be skipped.
*
* @inheritdoc
*
* @return list<IMountPoint>
*/
public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array {
$providers = array_filter(
$this->providers,
fn (IMountProvider $mountProvider) => (in_array(get_class($mountProvider), $mountProviderClasses))
fn (string $providerClass) => in_array($providerClass, $mountProviderClasses),
ARRAY_FILTER_USE_KEY
);
return $this->getUserMountsForProviders($user, $providers);
return $this->getUserMountsForProviders($user, array_values($providers));
}

/**
Expand All @@ -99,16 +137,21 @@ public function addMountForUser(IUser $user, IMountManager $mountManager, ?calla
// to check for name collisions
$firstMounts = [];
if ($providerFilter) {
$providers = array_filter($this->providers, $providerFilter);
$providers = array_filter($this->providers, $providerFilter, ARRAY_FILTER_USE_KEY);
} else {
$providers = $this->providers;
}
$firstProviders = array_filter($providers, function (IMountProvider $provider) {
return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
});
$lastProviders = array_filter($providers, function (IMountProvider $provider) {
return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
});
$firstProviders
= array_filter(
$providers,
fn (string $providerClass) => ($providerClass !== MountProvider::class),
ARRAY_FILTER_USE_KEY
);
$lastProviders = array_filter(
$providers,
fn (string $providerClass) => $providerClass === MountProvider::class,
ARRAY_FILTER_USE_KEY
);
foreach ($firstProviders as $provider) {
$mounts = $this->getMountsFromProvider($provider, $user, $this->loader);
$firstMounts = array_merge($firstMounts, $mounts);
Expand Down Expand Up @@ -150,7 +193,7 @@ public function getHomeMountForUser(IUser $user): IMountPoint {
* Add a provider for mount points
*/
public function registerProvider(IMountProvider $provider): void {
$this->providers[] = $provider;
$this->providers[get_class($provider)] = $provider;

$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
}
Expand Down Expand Up @@ -228,7 +271,7 @@ public function clearProviders(): void {
* @return list<IMountProvider>
*/
public function getProviders(): array {
return $this->providers;
return array_values($this->providers);
}

/**
Expand Down
Loading
Loading