1616use OCA \Files_External \MountConfig ;
1717use OCA \Files_External \Service \UserGlobalStoragesService ;
1818use OCA \Files_External \Service \UserStoragesService ;
19- use OCP \AppFramework \QueryException ;
2019use OCP \Files \Config \IAuthoritativeMountProvider ;
2120use OCP \Files \Config \IMountProvider ;
21+ use OCP \Files \Config \IPartialMountProvider ;
2222use OCP \Files \Mount \IMountPoint ;
2323use OCP \Files \ObjectStore \IObjectStore ;
2424use OCP \Files \Storage \IConstructableStorage ;
2727use OCP \Files \StorageNotAvailableException ;
2828use OCP \IUser ;
2929use OCP \Server ;
30+ use Override ;
3031use Psr \Clock \ClockInterface ;
32+ use Psr \Container \ContainerExceptionInterface ;
3133use Psr \Log \LoggerInterface ;
3234
3335/**
3436 * Make the old files_external config work with the new public mount config api
3537 */
36- class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider {
38+ class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider, IPartialMountProvider {
3739 public function __construct (
3840 private UserStoragesService $ userStoragesService ,
3941 private UserGlobalStoragesService $ userGlobalStoragesService ,
@@ -57,7 +59,7 @@ private function validateObjectStoreClassString(string $class): string {
5759 /**
5860 * Process storage ready for mounting
5961 *
60- * @throws QueryException
62+ * @throws ContainerExceptionInterface
6163 */
6264 private function prepareStorageConfig (StorageConfig &$ storage , IUser $ user ): void {
6365 foreach ($ storage ->getBackendOptions () as $ option => $ value ) {
@@ -81,8 +83,6 @@ public function constructStorageForUser(IUser $user, StorageConfig $storage) {
8183
8284 /**
8385 * Construct the storage implementation
84- *
85- * @param StorageConfig $storageConfig
8686 */
8787 private function constructStorage (StorageConfig $ storageConfig ): IStorage {
8888 $ class = $ storageConfig ->getBackend ()->getStorageClass ();
@@ -99,17 +99,12 @@ private function constructStorage(StorageConfig $storageConfig): IStorage {
9999 }
100100
101101 /**
102- * Get all mountpoints applicable for the user
103- *
104- * @return IMountPoint[]
102+ * @param list<StorageConfig> $storageConfigs
103+ * @return array
104+ * @throws ContainerExceptionInterface
105105 */
106- public function getMountsForUser (IUser $ user , IStorageFactory $ loader ) {
107- $ this ->userStoragesService ->setUser ($ user );
108- $ this ->userGlobalStoragesService ->setUser ($ user );
109-
110- $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUser ();
111-
112- $ storages = array_map (function (StorageConfig $ storageConfig ) use ($ user ) {
106+ private function getAvailableStorages (array $ storageConfigs , IUser $ user ): array {
107+ $ storages = array_map (function (StorageConfig $ storageConfig ) use ($ user ): IStorage {
113108 try {
114109 return $ this ->constructStorageForUser ($ user , $ storageConfig );
115110 } catch (\Exception $ e ) {
@@ -123,7 +118,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
123118 return $ storage ->getId ();
124119 }, $ storages ));
125120
126- $ availableStorages = array_map (function (IStorage $ storage , StorageConfig $ storageConfig ): IStorage {
121+ return array_map (function (IStorage $ storage , StorageConfig $ storageConfig ): IStorage {
127122 try {
128123 $ availability = $ storage ->getAvailability ();
129124 if (!$ availability ['available ' ] && !Availability::shouldRecheck ($ availability )) {
@@ -137,6 +132,19 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
137132 }
138133 return $ storage ;
139134 }, $ storages , $ storageConfigs );
135+ }
136+
137+ /**
138+ * Get all mountpoints applicable for the user
139+ *
140+ * @return IMountPoint[]
141+ */
142+ public function getMountsForUser (IUser $ user , IStorageFactory $ loader ): array {
143+ $ this ->userStoragesService ->setUser ($ user );
144+ $ this ->userGlobalStoragesService ->setUser ($ user );
145+
146+ $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUser ();
147+ $ availableStorages = $ this ->getAvailableStorages ($ storageConfigs , $ user );
140148
141149 $ mounts = array_map (function (StorageConfig $ storageConfig , IStorage $ storage ) use ($ user , $ loader ) {
142150 $ storage ->setOwner ($ user ->getUID ());
@@ -173,4 +181,74 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
173181
174182 return $ mounts ;
175183 }
184+
185+ #[Override]
186+ public function getMountsForPath (string $ path , bool $ forChildren , array $ mountProviderArgs , IStorageFactory $ loader ): array {
187+ if (empty ($ mountProviderArgs )) {
188+ return [];
189+ }
190+
191+ $ userId = null ;
192+ $ user = null ;
193+ foreach ($ mountProviderArgs as $ mountProviderArg ) {
194+ if ($ userId === null ) {
195+ $ user = $ mountProviderArg ->mountInfo ->getUser ();
196+ $ userId = $ user ->getUID ();
197+ } elseif ($ userId !== $ mountProviderArg ->mountInfo ->getUser ()->getUID ()) {
198+ throw new \LogicException ('Mounts must belong to the same user! ' );
199+ }
200+ }
201+
202+ if (!$ forChildren ) {
203+ // override path with mount point when fetching without children
204+ $ path = $ mountProviderArgs [0 ]->mountInfo ->getMountPoint (); // TODO: not sure what this is doing, is this getting the parent path?
205+ }
206+
207+ $ this ->userStoragesService ->setUser ($ user );
208+ $ this ->userGlobalStoragesService ->setUser ($ user );
209+
210+ $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUserWithPath ($ path , $ forChildren );
211+ $ availableStorages = $ this ->getAvailableStorages ($ storageConfigs , $ user );
212+
213+ $ mounts = [];
214+
215+ $ i = 0 ;
216+ foreach ($ storageConfigs as $ storageConfig ) {
217+ $ storage = $ availableStorages [$ i ];
218+ $ i ++;
219+ $ storage ->setOwner ($ user ->getUID ());
220+ $ mountPoint = '/ ' . $ user ->getUID () . '/files ' . $ storageConfig ->getMountPoint ();
221+ if ($ storageConfig ->getType () === StorageConfig::MOUNT_TYPE_PERSONAL ) {
222+ $ mounts [$ mountPoint ] = new PersonalMount (
223+ $ this ->userStoragesService ,
224+ $ storageConfig ,
225+ $ storageConfig ->getId (),
226+ new KnownMtime ([
227+ 'storage ' => $ storage ,
228+ 'clock ' => $ this ->clock ,
229+ ]),
230+ $ mountPoint ,
231+ null ,
232+ $ loader ,
233+ $ storageConfig ->getMountOptions (),
234+ $ storageConfig ->getId ()
235+ );
236+ } else {
237+ $ mounts [$ mountPoint ] = new SystemMountPoint (
238+ $ storageConfig ,
239+ $ storage ,
240+ $ mountPoint ,
241+ null ,
242+ $ loader ,
243+ $ storageConfig ->getMountOptions (),
244+ $ storageConfig ->getId ()
245+ );
246+ }
247+ }
248+
249+ $ this ->userStoragesService ->resetUser ();
250+ $ this ->userGlobalStoragesService ->resetUser ();
251+
252+ return $ mounts ;
253+ }
176254}
0 commit comments