1515use OCP \EventDispatcher \IEventListener ;
1616use OCP \Files \Config \ICachedMountInfo ;
1717use OCP \Files \Config \IUserMountCache ;
18+ use OCP \Files \Storage \IStorageFactory ;
1819use OCP \Group \Events \UserAddedEvent ;
1920use OCP \Group \Events \UserRemovedEvent ;
2021use OCP \IUser ;
@@ -33,6 +34,7 @@ public function __construct(
3334 private readonly IUserMountCache $ userMountCache ,
3435 private readonly MountProvider $ shareMountProvider ,
3536 private readonly ShareTargetValidator $ shareTargetValidator ,
37+ private readonly IStorageFactory $ storageFactory ,
3638 ) {
3739 }
3840
@@ -49,18 +51,26 @@ public function handle(Event $event): void {
4951
5052 private function updateForUser (IUser $ user ): void {
5153 $ cachedMounts = $ this ->userMountCache ->getMountsForUser ($ user );
54+ $ shareMounts = array_filter ($ cachedMounts , fn (ICachedMountInfo $ mount ) => $ mount ->getMountProvider () === MountProvider::class);
5255 $ mountPoints = array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts );
5356 $ mountsByPath = array_combine ($ mountPoints , $ cachedMounts );
5457
5558 $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user );
5659
60+ $ mountsChanged = count ($ shares ) !== count ($ shareMounts );
5761 foreach ($ shares as &$ share ) {
5862 [$ parentShare , $ groupedShares ] = $ share ;
5963 $ mountPoint = '/ ' . $ user ->getUID () . '/files/ ' . trim ($ parentShare ->getTarget (), '/ ' ) . '/ ' ;
6064 $ mountKey = $ parentShare ->getNodeId () . ':: ' . $ mountPoint ;
6165 if (!isset ($ cachedMounts [$ mountKey ])) {
66+ $ mountsChanged = true ;
6267 $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
6368 }
6469 }
70+
71+ if ($ mountsChanged ) {
72+ $ newMounts = $ this ->shareMountProvider ->getMountsFromSuperShares ($ user , $ shares , $ this ->storageFactory );
73+ $ this ->userMountCache ->registerMounts ($ user , $ newMounts , [MountProvider::class]);
74+ }
6575 }
6676}
0 commit comments