99
1010use OC \Hooks \Emitter ;
1111use OC \Hooks \EmitterTrait ;
12+ use OCA \Files_Sharing \MountProvider ;
1213use OCP \Diagnostics \IEventLogger ;
1314use OCP \Files \Config \IHomeMountProvider ;
1415use OCP \Files \Config \IMountProvider ;
16+ use OCP \Files \Config \IMountProviderArgs ;
1517use OCP \Files \Config \IMountProviderCollection ;
18+ use OCP \Files \Config \IPartialMountProvider ;
1619use OCP \Files \Config \IRootMountProvider ;
1720use OCP \Files \Config \IUserMountCache ;
1821use OCP \Files \Mount \IMountManager ;
1922use OCP \Files \Mount \IMountPoint ;
2023use OCP \Files \Storage \IStorageFactory ;
2124use OCP \IUser ;
25+ use function get_class ;
26+ use function in_array ;
2227
2328class MountProviderCollection implements IMountProviderCollection, Emitter {
2429 use EmitterTrait;
@@ -29,7 +34,7 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
2934 private array $ homeProviders = [];
3035
3136 /**
32- * @var list< IMountProvider>
37+ * @var array<class-string<IMountProvider>, IMountProvider>
3338 */
3439 private array $ providers = [];
3540
@@ -75,19 +80,51 @@ private function getUserMountsForProviders(IUser $user, array $providers): array
7580 * @return list<IMountPoint>
7681 */
7782 public function getMountsForUser (IUser $ user ): array {
78- return $ this ->getUserMountsForProviders ($ user , $ this ->providers );
83+ return $ this ->getUserMountsForProviders ($ user , array_values ($ this ->providers ));
84+ }
85+
86+ /**
87+ * @param IMountProviderArgs[] $mountProviderArgs
88+ * @return array<string, IMountPoint> IMountPoint array indexed by mount
89+ * point.
90+ */
91+ public function getUserMountsFromProviderByPath (
92+ string $ providerClass ,
93+ string $ path ,
94+ array $ mountProviderArgs ,
95+ ): array {
96+ $ provider = $ this ->providers [$ providerClass ] ?? null ;
97+ if ($ provider === null ) {
98+ return [];
99+ }
100+
101+ if (!is_a ($ providerClass , IPartialMountProvider::class, true )) {
102+ throw new \LogicException (
103+ 'Mount provider does not support partial mounts '
104+ );
105+ }
106+
107+ /** @var IPartialMountProvider $provider */
108+ return $ provider ->getMountsFromMountPoints (
109+ $ path ,
110+ $ mountProviderArgs ,
111+ $ this ->loader ,
112+ );
79113 }
80114
81115 /**
82116 * Returns the mounts for the user from the specified provider classes.
83117 * Providers not registered in the MountProviderCollection will be skipped.
84118 *
119+ * @inheritdoc
120+ *
85121 * @return list<IMountPoint>
86122 */
87123 public function getUserMountsForProviderClasses (IUser $ user , array $ mountProviderClasses ): array {
88124 $ providers = array_filter (
89125 $ this ->providers ,
90- fn (IMountProvider $ mountProvider ) => (in_array (get_class ($ mountProvider ), $ mountProviderClasses ))
126+ fn (string $ providerClass ) => in_array ($ providerClass , $ mountProviderClasses ),
127+ ARRAY_FILTER_USE_KEY
91128 );
92129 return $ this ->getUserMountsForProviders ($ user , $ providers );
93130 }
@@ -100,16 +137,21 @@ public function addMountForUser(IUser $user, IMountManager $mountManager, ?calla
100137 // to check for name collisions
101138 $ firstMounts = [];
102139 if ($ providerFilter ) {
103- $ providers = array_filter ($ this ->providers , $ providerFilter );
140+ $ providers = array_filter ($ this ->providers , $ providerFilter, ARRAY_FILTER_USE_KEY );
104141 } else {
105142 $ providers = $ this ->providers ;
106143 }
107- $ firstProviders = array_filter ($ providers , function (IMountProvider $ provider ) {
108- return (get_class ($ provider ) !== 'OCA\Files_Sharing\MountProvider ' );
109- });
110- $ lastProviders = array_filter ($ providers , function (IMountProvider $ provider ) {
111- return (get_class ($ provider ) === 'OCA\Files_Sharing\MountProvider ' );
112- });
144+ $ firstProviders
145+ = array_filter (
146+ $ providers ,
147+ fn (string $ providerClass ) => ($ providerClass !== MountProvider::class),
148+ ARRAY_FILTER_USE_KEY
149+ );
150+ $ lastProviders = array_filter (
151+ $ providers ,
152+ fn (string $ providerClass ) => $ providerClass === MountProvider::class,
153+ ARRAY_FILTER_USE_KEY
154+ );
113155 foreach ($ firstProviders as $ provider ) {
114156 $ mounts = $ this ->getMountsFromProvider ($ provider , $ user , $ this ->loader );
115157 $ firstMounts = array_merge ($ firstMounts , $ mounts );
@@ -151,7 +193,7 @@ public function getHomeMountForUser(IUser $user): IMountPoint {
151193 * Add a provider for mount points
152194 */
153195 public function registerProvider (IMountProvider $ provider ): void {
154- $ this ->providers [] = $ provider ;
196+ $ this ->providers [get_class ( $ provider ) ] = $ provider ;
155197
156198 $ this ->emit ('\OC\Files\Config ' , 'registerMountProvider ' , [$ provider ]);
157199 }
@@ -229,7 +271,7 @@ public function clearProviders(): void {
229271 * @return list<IMountProvider>
230272 */
231273 public function getProviders (): array {
232- return $ this ->providers ;
274+ return array_values ( $ this ->providers ) ;
233275 }
234276
235277 /**
0 commit comments