1818use OCA \Files_External \Service \UserStoragesService ;
1919use OCP \AppFramework \QueryException ;
2020use OCP \Files \Config \IMountProvider ;
21+ use OCP \Files \Config \IPartialMountProvider ;
2122use OCP \Files \Mount \IMountPoint ;
2223use OCP \Files \ObjectStore \IObjectStore ;
2324use OCP \Files \Storage \IConstructableStorage ;
2627use OCP \Files \StorageNotAvailableException ;
2728use OCP \IUser ;
2829use OCP \Server ;
30+ use Override ;
2931use Psr \Clock \ClockInterface ;
32+ use Psr \Container \ContainerExceptionInterface ;
3033use Psr \Log \LoggerInterface ;
3134
3235/**
3336 * Make the old files_external config work with the new public mount config api
3437 */
35- class ConfigAdapter implements IMountProvider {
38+ class ConfigAdapter implements IMountProvider, IPartialMountProvider {
3639 public function __construct (
3740 private UserStoragesService $ userStoragesService ,
3841 private UserGlobalStoragesService $ userGlobalStoragesService ,
@@ -56,7 +59,7 @@ private function validateObjectStoreClassString(string $class): string {
5659 /**
5760 * Process storage ready for mounting
5861 *
59- * @throws QueryException
62+ * @throws ContainerExceptionInterface
6063 */
6164 private function prepareStorageConfig (StorageConfig &$ storage , IUser $ user ): void {
6265 foreach ($ storage ->getBackendOptions () as $ option => $ value ) {
@@ -75,8 +78,6 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user): voi
7578
7679 /**
7780 * Construct the storage implementation
78- *
79- * @param StorageConfig $storageConfig
8081 */
8182 private function constructStorage (StorageConfig $ storageConfig ): IStorage {
8283 $ class = $ storageConfig ->getBackend ()->getStorageClass ();
@@ -93,17 +94,12 @@ private function constructStorage(StorageConfig $storageConfig): IStorage {
9394 }
9495
9596 /**
96- * Get all mountpoints applicable for the user
97- *
98- * @return IMountPoint[]
97+ * @param list<StorageConfig> $storageConfigs
98+ * @return array
99+ * @throws ContainerExceptionInterface
99100 */
100- public function getMountsForUser (IUser $ user , IStorageFactory $ loader ) {
101- $ this ->userStoragesService ->setUser ($ user );
102- $ this ->userGlobalStoragesService ->setUser ($ user );
103-
104- $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUser ();
105-
106- $ storages = array_map (function (StorageConfig $ storageConfig ) use ($ user ) {
101+ private function getAvailableStorages (array $ storageConfigs , IUser $ user ): array {
102+ $ storages = array_map (function (StorageConfig $ storageConfig ) use ($ user ): IStorage {
107103 try {
108104 $ this ->prepareStorageConfig ($ storageConfig , $ user );
109105 return $ this ->constructStorage ($ storageConfig );
@@ -118,7 +114,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
118114 return $ storage ->getId ();
119115 }, $ storages ));
120116
121- $ availableStorages = array_map (function (IStorage $ storage , StorageConfig $ storageConfig ): IStorage {
117+ return array_map (function (IStorage $ storage , StorageConfig $ storageConfig ): IStorage {
122118 try {
123119 $ availability = $ storage ->getAvailability ();
124120 if (!$ availability ['available ' ] && !Availability::shouldRecheck ($ availability )) {
@@ -132,6 +128,19 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
132128 }
133129 return $ storage ;
134130 }, $ storages , $ storageConfigs );
131+ }
132+
133+ /**
134+ * Get all mountpoints applicable for the user
135+ *
136+ * @return IMountPoint[]
137+ */
138+ public function getMountsForUser (IUser $ user , IStorageFactory $ loader ): array {
139+ $ this ->userStoragesService ->setUser ($ user );
140+ $ this ->userGlobalStoragesService ->setUser ($ user );
141+
142+ $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUser ();
143+ $ availableStorages = $ this ->getAvailableStorages ($ storageConfigs , $ user );
135144
136145 $ mounts = array_map (function (StorageConfig $ storageConfig , IStorage $ storage ) use ($ user , $ loader ) {
137146 $ storage ->setOwner ($ user ->getUID ());
@@ -168,4 +177,74 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
168177
169178 return $ mounts ;
170179 }
180+
181+ #[Override]
182+ public function getMountsForPath (string $ path , bool $ forChildren , array $ mountProviderArgs , IStorageFactory $ loader ): array {
183+ if (empty ($ mountProviderArgs )) {
184+ return [];
185+ }
186+
187+ $ userId = null ;
188+ $ user = null ;
189+ foreach ($ mountProviderArgs as $ mountProviderArg ) {
190+ if ($ userId === null ) {
191+ $ user = $ mountProviderArg ->mountInfo ->getUser ();
192+ $ userId = $ user ->getUID ();
193+ } elseif ($ userId !== $ mountProviderArg ->mountInfo ->getUser ()->getUID ()) {
194+ throw new \LogicException ('Mounts must belong to the same user! ' );
195+ }
196+ }
197+
198+ if (!$ forChildren ) {
199+ // override path with mount point when fetching without children
200+ $ path = $ mountProviderArgs [0 ]->mountInfo ->getMountPoint (); // TODO: not sure what this is doing, is this getting the parent path?
201+ }
202+
203+ $ this ->userStoragesService ->setUser ($ user );
204+ $ this ->userGlobalStoragesService ->setUser ($ user );
205+
206+ $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUserWithPath ($ path , $ forChildren );
207+ $ availableStorages = $ this ->getAvailableStorages ($ storageConfigs , $ user );
208+
209+ $ mounts = [];
210+
211+ $ i = 0 ;
212+ foreach ($ storageConfigs as $ storageConfig ) {
213+ $ storage = $ availableStorages [$ i ];
214+ $ i ++;
215+ $ storage ->setOwner ($ user ->getUID ());
216+ $ mountPoint = '/ ' . $ user ->getUID () . '/files ' . $ storageConfig ->getMountPoint ();
217+ if ($ storageConfig ->getType () === StorageConfig::MOUNT_TYPE_PERSONAL ) {
218+ $ mounts [$ mountPoint ] = new PersonalMount (
219+ $ this ->userStoragesService ,
220+ $ storageConfig ,
221+ $ storageConfig ->getId (),
222+ new KnownMtime ([
223+ 'storage ' => $ storage ,
224+ 'clock ' => $ this ->clock ,
225+ ]),
226+ $ mountPoint ,
227+ null ,
228+ $ loader ,
229+ $ storageConfig ->getMountOptions (),
230+ $ storageConfig ->getId ()
231+ );
232+ } else {
233+ $ mounts [$ mountPoint ] = new SystemMountPoint (
234+ $ storageConfig ,
235+ $ storage ,
236+ $ mountPoint ,
237+ null ,
238+ $ loader ,
239+ $ storageConfig ->getMountOptions (),
240+ $ storageConfig ->getId ()
241+ );
242+ }
243+ }
244+
245+ $ this ->userStoragesService ->resetUser ();
246+ $ this ->userGlobalStoragesService ->resetUser ();
247+
248+ return $ mounts ;
249+ }
171250}
0 commit comments