@@ -37,6 +37,7 @@ public function __construct(
3737 private readonly IUserMountCache $ userMountCache ,
3838 private readonly MountProvider $ shareMountProvider ,
3939 private readonly ShareTargetValidator $ shareTargetValidator ,
40+ private readonly IStorageFactory $ storageFactory ,
4041 ) {
4142 $ this ->updatedUsers = new CappedMemoryCache ();
4243 }
@@ -46,38 +47,52 @@ public function handle(Event $event): void {
4647 }
4748 if ($ event instanceof UserShareAccessUpdatedEvent) {
4849 foreach ($ event ->getUsers () as $ user ) {
49- $ this ->updateForUser ($ user );
50+ $ this ->updateForUser ($ user, true );
5051 }
5152 }
5253 if ($ event instanceof UserAddedEvent || $ event instanceof UserRemovedEvent) {
53- $ this ->updateForUser ($ event ->getUser ());
54+ $ this ->updateForUser ($ event ->getUser (), true );
5455 }
55- if ($ event instanceof ShareCreatedEvent || $ event instanceof BeforeShareDeletedEvent ) {
56+ if ($ event instanceof ShareCreatedEvent) {
5657 foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
57- $ this ->updateForUser ($ user );
58+ $ this ->updateForUser ($ user , true );
59+ }
60+ }
61+ if ($ event instanceof BeforeShareDeletedEvent) {
62+ foreach ($ this ->shareManager ->getUsersForShare ($ event ->getShare ()) as $ user ) {
63+ $ this ->updateForUser ($ user , false , [$ event ->getShare ()]);
5864 }
5965 }
6066 }
6167
62- private function updateForUser (IUser $ user ): void {
68+ private function updateForUser (IUser $ user, bool $ verifyMountPoints , array $ ignoreShares = [] ): void {
6369 if (isset ($ this ->updatedUsers [$ user ->getUID ()])) {
6470 return ;
6571 }
6672 $ this ->updatedUsers [$ user ->getUID ()] = true ;
67-
6873 $ cachedMounts = $ this ->userMountCache ->getMountsForUser ($ user );
74+ $ shareMounts = array_filter ($ cachedMounts , fn (ICachedMountInfo $ mount ) => $ mount ->getMountProvider () === MountProvider::class);
6975 $ mountPoints = array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts );
7076 $ mountsByPath = array_combine ($ mountPoints , $ cachedMounts );
7177
72- $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user );
78+ $ shares = $ this ->shareMountProvider ->getSuperSharesForUser ($ user, $ ignoreShares );
7379
80+ $ mountsChanged = count ($ shares ) !== count ($ shareMounts );
7481 foreach ($ shares as &$ share ) {
7582 [$ parentShare , $ groupedShares ] = $ share ;
7683 $ mountPoint = '/ ' . $ user ->getUID () . '/files/ ' . trim ($ parentShare ->getTarget (), '/ ' ) . '/ ' ;
7784 $ mountKey = $ parentShare ->getNodeId () . ':: ' . $ mountPoint ;
7885 if (!isset ($ cachedMounts [$ mountKey ])) {
79- $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
86+ $ mountsChanged = true ;
87+ if ($ verifyMountPoints ) {
88+ $ this ->shareTargetValidator ->verifyMountPoint ($ user , $ parentShare , $ mountsByPath , $ groupedShares );
89+ }
8090 }
8191 }
92+
93+ if ($ mountsChanged ) {
94+ $ newMounts = $ this ->shareMountProvider ->getMountsFromSuperShares ($ user , $ shares , $ this ->storageFactory );
95+ $ this ->userMountCache ->registerMounts ($ user , $ newMounts , [MountProvider::class]);
96+ }
8297 }
8398}
0 commit comments