4949use OCP \Files \Mount \IMountPoint ;
5050use OCP \Files \NotFoundException ;
5151use OCP \Files \Storage \IStorage ;
52+ use OCP \Files \Storage \IStorageFactory ;
5253use OCP \Group \Events \UserAddedEvent ;
5354use OCP \Group \Events \UserRemovedEvent ;
5455use OCP \HintException ;
@@ -115,6 +116,7 @@ public function __construct(
115116 private IAppManager $ appManager ,
116117 private FileAccess $ fileAccess ,
117118 private IAppConfig $ appConfig ,
119+ private IStorageFactory $ storageFactory ,
118120 ) {
119121 $ this ->cache = $ cacheFactory ->createDistributed ('setupmanager:: ' );
120122 $ this ->listeningForProviders = false ;
@@ -154,28 +156,30 @@ private function isPathSetup(string $path): bool {
154156 return false ;
155157 }
156158
157- private function setupBuiltinWrappers (): void {
159+ /**
160+ * @param IMountPoint[] $existingMounts
161+ */
162+ private function setupBuiltinWrappers (array $ existingMounts ): void {
158163 if ($ this ->setupBuiltinWrappersDone ) {
159164 return ;
160165 }
161166 $ this ->setupBuiltinWrappersDone = true ;
162167
163168 // load all filesystem apps before, so no setup-hook gets lost
164169 $ this ->appManager ->loadApps (['filesystem ' ]);
165- $ prevLogging = Filesystem::logWarningWhenAddingStorageWrapper (false );
166170
167- Filesystem:: addStorageWrapper ('mount_options ' , function ($ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
171+ $ this -> storageFactory -> addStorageWrapper ('mount_options ' , function (string $ mountPoint , IStorage $ storage , IMountPoint $ mount ): IStorage {
168172 if ($ storage ->instanceOfStorage (Common::class)) {
169173 $ options = array_merge ($ mount ->getOptions (), ['mount_point ' => $ mountPoint ]);
170174 $ storage ->setMountOptions ($ options );
171175 }
172176 return $ storage ;
173- });
177+ }, 50 , $ existingMounts );
174178
175179 $ reSharingEnabled = $ this ->appConfig ->getValueBool ('core ' , 'shareapi_allow_resharing ' , true );
176180 $ user = $ this ->userSession ->getUser ();
177181 $ sharingEnabledForUser = $ user ? !$ this ->shareDisableChecker ->sharingDisabledForUser ($ user ->getUID ()) : true ;
178- Filesystem:: addStorageWrapper (
182+ $ this -> storageFactory -> addStorageWrapper (
179183 'sharing_mask ' ,
180184 function ($ mountPoint , IStorage $ storage , IMountPoint $ mount ) use ($ reSharingEnabled , $ sharingEnabledForUser ) {
181185 $ sharingEnabledForMount = $ mount ->getOption ('enable_sharing ' , true );
@@ -187,27 +191,26 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
187191 ]);
188192 }
189193 return $ storage ;
190- }
191- );
194+ }, 50 , $ existingMounts );
192195
193196 // install storage availability wrapper, before most other wrappers
194- Filesystem:: addStorageWrapper (' oc_availability ' , function ($ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
197+ $ this -> storageFactory -> addStorageWrapper (Availability::class , function (string $ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
195198 $ externalMount = $ mount instanceof ExternalMountPoint || $ mount instanceof Mount;
196199 if ($ externalMount && !$ storage ->isLocal ()) {
197200 return new Availability (['storage ' => $ storage ]);
198201 }
199202 return $ storage ;
200- });
203+ }, 50 , $ existingMounts );
201204
202- Filesystem:: addStorageWrapper (' oc_encoding ' , function ($ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
205+ $ this -> storageFactory -> addStorageWrapper (Encoding::class , function (string $ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
203206 if ($ mount ->getOption ('encoding_compatibility ' , false ) && !$ mount instanceof SharedMount) {
204207 return new Encoding (['storage ' => $ storage ]);
205208 }
206209 return $ storage ;
207- });
210+ }, 50 , $ existingMounts );
208211
209212 $ quotaIncludeExternal = $ this ->config ->getSystemValue ('quota_include_external_storage ' , false );
210- Filesystem:: addStorageWrapper (' oc_quota ' , function ($ mountPoint , $ storage , IMountPoint $ mount ) use ($ quotaIncludeExternal ) {
213+ $ this -> storageFactory -> addStorageWrapper (Quota::class , function ($ mountPoint , $ storage , IMountPoint $ mount ) use ($ quotaIncludeExternal ) {
211214 // set up quota for home storages, even for other users
212215 // which can happen when using sharing
213216 if ($ mount instanceof HomeMountPoint) {
@@ -218,9 +221,9 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
218221 }
219222
220223 return $ storage ;
221- });
224+ }, 50 , $ existingMounts );
222225
223- Filesystem:: addStorageWrapper ('readonly ' , function ($ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
226+ $ this -> storageFactory -> addStorageWrapper ('readonly ' , function (string $ mountPoint , IStorage $ storage , IMountPoint $ mount ) {
224227 /*
225228 * Do not allow any operations that modify the storage
226229 */
@@ -235,9 +238,7 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna
235238 ]);
236239 }
237240 return $ storage ;
238- });
239-
240- Filesystem::logWarningWhenAddingStorageWrapper ($ prevLogging );
241+ }, 50 , $ existingMounts );
241242 }
242243
243244 /**
@@ -299,7 +300,7 @@ public function setupForUser(IUser $user): void {
299300 /**
300301 * Part of the user setup that is run only once per user.
301302 */
302- private function oneTimeUserSetup (IUser $ user ) {
303+ private function oneTimeUserSetup (IUser $ user ): void {
303304 if ($ this ->isSetupStarted ($ user )) {
304305 return ;
305306 }
@@ -309,22 +310,24 @@ private function oneTimeUserSetup(IUser $user) {
309310
310311 $ this ->eventLogger ->start ('fs:setup:user:onetime ' , 'Onetime filesystem for user ' );
311312
312- $ this ->setupBuiltinWrappers ();
313-
314- $ prevLogging = Filesystem::logWarningWhenAddingStorageWrapper (false );
313+ $ mounts = $ this ->mountManager ->getAll ();
314+ $ this ->setupBuiltinWrappers ($ mounts );
315315
316316 // TODO remove hook
317+ $ prevLogging = Filesystem::logWarningWhenAddingStorageWrapper (false );
317318 OC_Hook::emit ('OC_Filesystem ' , 'preSetup ' , ['user ' => $ user ->getUID ()]);
318319
319320 $ event = new BeforeFileSystemSetupEvent ($ user );
320321 $ this ->eventDispatcher ->dispatchTyped ($ event );
322+ Filesystem::logWarningWhenAddingStorageWrapper ($ prevLogging );
321323
322- foreach ($ event ->getStorageWrappers () as $ name => $ wrapper ) {
323- Filesystem::addStorageWrapper ($ name , $ wrapper ['wrapper ' ], $ wrapper ['priority ' ]);
324+ $ storageWrappers = $ event ->getStorageWrappers ();
325+ if ($ storageWrappers !== []) {
326+ foreach ($ storageWrappers as $ wrapperName => $ wrapper ) {
327+ $ this ->storageFactory ->addStorageWrapper ($ wrapperName , $ wrapper ['callable ' ], $ wrapper ['priority ' ], $ mounts );
328+ }
324329 }
325330
326- Filesystem::logWarningWhenAddingStorageWrapper ($ prevLogging );
327-
328331 $ userDir = '/ ' . $ user ->getUID () . '/files ' ;
329332
330333 Filesystem::initInternal ($ userDir );
@@ -430,7 +433,8 @@ public function setupRoot(): void {
430433 return ;
431434 }
432435
433- $ this ->setupBuiltinWrappers ();
436+ $ mounts = $ this ->mountManager ->getAll ();
437+ $ this ->setupBuiltinWrappers ($ mounts );
434438
435439 $ this ->rootSetup = true ;
436440
@@ -776,7 +780,7 @@ private function listenForNewMountProviders() {
776780 }
777781 }
778782
779- private function setupListeners () {
783+ private function setupListeners (): void {
780784 // note that this event handling is intentionally pessimistic
781785 // clearing the cache to often is better than not enough
782786
0 commit comments