1919use OCP \AppFramework \QueryException ;
2020use OCP \Files \Config \IAuthoritativeMountProvider ;
2121use OCP \Files \Config \IMountProvider ;
22+ use OCP \Files \Config \IPartialMountProvider ;
2223use OCP \Files \Mount \IMountPoint ;
2324use OCP \Files \ObjectStore \IObjectStore ;
2425use OCP \Files \Storage \IConstructableStorage ;
2728use OCP \Files \StorageNotAvailableException ;
2829use OCP \IUser ;
2930use OCP \Server ;
31+ use Override ;
3032use Psr \Clock \ClockInterface ;
33+ use Psr \Container \ContainerExceptionInterface ;
3134use Psr \Log \LoggerInterface ;
3235
3336/**
3437 * Make the old files_external config work with the new public mount config api
3538 */
36- class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider {
39+ class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider, IPartialMountProvider {
3740 public function __construct (
3841 private UserStoragesService $ userStoragesService ,
3942 private UserGlobalStoragesService $ userGlobalStoragesService ,
@@ -57,7 +60,7 @@ private function validateObjectStoreClassString(string $class): string {
5760 /**
5861 * Process storage ready for mounting
5962 *
60- * @throws QueryException
63+ * @throws ContainerExceptionInterface
6164 */
6265 private function prepareStorageConfig (StorageConfig &$ storage , IUser $ user ): void {
6366 foreach ($ storage ->getBackendOptions () as $ option => $ value ) {
@@ -81,8 +84,6 @@ public function constructStorageForUser(IUser $user, StorageConfig $storage) {
8184
8285 /**
8386 * Construct the storage implementation
84- *
85- * @param StorageConfig $storageConfig
8687 */
8788 private function constructStorage (StorageConfig $ storageConfig ): IStorage {
8889 $ class = $ storageConfig ->getBackend ()->getStorageClass ();
@@ -99,17 +100,12 @@ private function constructStorage(StorageConfig $storageConfig): IStorage {
99100 }
100101
101102 /**
102- * Get all mountpoints applicable for the user
103- *
104- * @return IMountPoint[]
103+ * @param list<StorageConfig> $storageConfigs
104+ * @return array
105+ * @throws ContainerExceptionInterface
105106 */
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 ) {
107+ private function getAvailableStorages (array $ storageConfigs , IUser $ user ): array {
108+ $ storages = array_map (function (StorageConfig $ storageConfig ) use ($ user ): IStorage {
113109 try {
114110 return $ this ->constructStorageForUser ($ user , $ storageConfig );
115111 } catch (\Exception $ e ) {
@@ -123,7 +119,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
123119 return $ storage ->getId ();
124120 }, $ storages ));
125121
126- $ availableStorages = array_map (function (IStorage $ storage , StorageConfig $ storageConfig ): IStorage {
122+ return array_map (function (IStorage $ storage , StorageConfig $ storageConfig ): IStorage {
127123 try {
128124 $ availability = $ storage ->getAvailability ();
129125 if (!$ availability ['available ' ] && !Availability::shouldRecheck ($ availability )) {
@@ -137,6 +133,19 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
137133 }
138134 return $ storage ;
139135 }, $ storages , $ storageConfigs );
136+ }
137+
138+ /**
139+ * Get all mountpoints applicable for the user
140+ *
141+ * @return IMountPoint[]
142+ */
143+ public function getMountsForUser (IUser $ user , IStorageFactory $ loader ): array {
144+ $ this ->userStoragesService ->setUser ($ user );
145+ $ this ->userGlobalStoragesService ->setUser ($ user );
146+
147+ $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUser ();
148+ $ availableStorages = $ this ->getAvailableStorages ($ storageConfigs , $ user );
140149
141150 $ mounts = array_map (function (StorageConfig $ storageConfig , IStorage $ storage ) use ($ user , $ loader ) {
142151 $ storage ->setOwner ($ user ->getUID ());
@@ -173,4 +182,74 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
173182
174183 return $ mounts ;
175184 }
185+
186+ #[Override]
187+ public function getMountsForPath (string $ path , bool $ forChildren , array $ mountProviderArgs , IStorageFactory $ loader ): array {
188+ if (empty ($ mountProviderArgs )) {
189+ return [];
190+ }
191+
192+ $ userId = null ;
193+ $ user = null ;
194+ foreach ($ mountProviderArgs as $ mountProviderArg ) {
195+ if ($ userId === null ) {
196+ $ user = $ mountProviderArg ->mountInfo ->getUser ();
197+ $ userId = $ user ->getUID ();
198+ } elseif ($ userId !== $ mountProviderArg ->mountInfo ->getUser ()->getUID ()) {
199+ throw new \LogicException ('Mounts must belong to the same user! ' );
200+ }
201+ }
202+
203+ if (!$ forChildren ) {
204+ // override path with mount point when fetching without children
205+ $ path = $ mountProviderArgs [0 ]->mountInfo ->getMountPoint (); // TODO: not sure what this is doing, is this getting the parent path?
206+ }
207+
208+ $ this ->userStoragesService ->setUser ($ user );
209+ $ this ->userGlobalStoragesService ->setUser ($ user );
210+
211+ $ storageConfigs = $ this ->userGlobalStoragesService ->getAllStoragesForUserWithPath ($ path , $ forChildren );
212+ $ availableStorages = $ this ->getAvailableStorages ($ storageConfigs , $ user );
213+
214+ $ mounts = [];
215+
216+ $ i = 0 ;
217+ foreach ($ storageConfigs as $ storageConfig ) {
218+ $ storage = $ availableStorages [$ i ];
219+ $ i ++;
220+ $ storage ->setOwner ($ user ->getUID ());
221+ $ mountPoint = '/ ' . $ user ->getUID () . '/files ' . $ storageConfig ->getMountPoint ();
222+ if ($ storageConfig ->getType () === StorageConfig::MOUNT_TYPE_PERSONAL ) {
223+ $ mounts [$ mountPoint ] = new PersonalMount (
224+ $ this ->userStoragesService ,
225+ $ storageConfig ,
226+ $ storageConfig ->getId (),
227+ new KnownMtime ([
228+ 'storage ' => $ storage ,
229+ 'clock ' => $ this ->clock ,
230+ ]),
231+ $ mountPoint ,
232+ null ,
233+ $ loader ,
234+ $ storageConfig ->getMountOptions (),
235+ $ storageConfig ->getId ()
236+ );
237+ } else {
238+ $ mounts [$ mountPoint ] = new SystemMountPoint (
239+ $ storageConfig ,
240+ $ storage ,
241+ $ mountPoint ,
242+ null ,
243+ $ loader ,
244+ $ storageConfig ->getMountOptions (),
245+ $ storageConfig ->getId ()
246+ );
247+ }
248+ }
249+
250+ $ this ->userStoragesService ->resetUser ();
251+ $ this ->userGlobalStoragesService ->resetUser ();
252+
253+ return $ mounts ;
254+ }
176255}
0 commit comments