1111use InvalidArgumentException ;
1212use OC \Files \View ;
1313use OCA \Files_Sharing \Event \ShareMountedEvent ;
14- use OCP \Cache \CappedMemoryCache ;
1514use OCP \EventDispatcher \IEventDispatcher ;
1615use OCP \Files \Config \IMountProvider ;
1716use OCP \Files \Config \IPartialMountProvider ;
2423use OCP \Share \IAttributes ;
2524use OCP \Share \IManager ;
2625use OCP \Share \IShare ;
26+ use Override ;
2727use Psr \Log \LoggerInterface ;
2828
2929use function count ;
3030
3131class MountProvider implements IMountProvider, IPartialMountProvider {
32- /**
33- * @param IConfig $config
34- * @param IManager $shareManager
35- * @param LoggerInterface $logger
36- */
3732 public function __construct (
38- protected IConfig $ config ,
39- protected IManager $ shareManager ,
40- protected LoggerInterface $ logger ,
41- protected IEventDispatcher $ eventDispatcher ,
42- protected ICacheFactory $ cacheFactory ,
43- protected IMountManager $ mountManager ,
33+ protected readonly IConfig $ config ,
34+ protected readonly IManager $ shareManager ,
35+ protected readonly LoggerInterface $ logger ,
36+ protected readonly IEventDispatcher $ eventDispatcher ,
37+ protected readonly ICacheFactory $ cacheFactory ,
38+ protected readonly IMountManager $ mountManager ,
4439 ) {
4540 }
4641
47- /**
48- * Get all mountpoints applicable for the user and check for shares where we need to update the etags
49- *
50- * @param IUser $user
51- * @param IStorageFactory $loader
52- * @return IMountPoint[]
53- */
54- public function getMountsForUser (IUser $ user , IStorageFactory $ loader ) {
42+ #[Override]
43+ public function getMountsForUser (IUser $ user , IStorageFactory $ loader ): array {
5544 return array_values ($ this ->getMountsFromSuperShares ($ user , $ this ->getSuperSharesForUser ($ user ), $ loader ));
5645 }
5746
@@ -77,8 +66,8 @@ public function getSuperSharesForUser(IUser $user): array {
7766 * Groups shares by path (nodeId) and target path
7867 *
7968 * @param iterable<IShare> $shares
80- * @return IShare[][] array of grouped shares, each element in the
81- * array is a group which itself is an array of shares
69+ * @return list<list< IShare>> array of grouped shares, each element in the
70+ * array is a group which itself is an array of shares
8271 */
8372 private function groupShares (iterable $ shares ): array {
8473 $ tmp = [];
@@ -98,9 +87,9 @@ private function groupShares(iterable $shares): array {
9887 $ aTime = $ a ->getShareTime ()->getTimestamp ();
9988 $ bTime = $ b ->getShareTime ()->getTimestamp ();
10089 if ($ aTime === $ bTime ) {
101- return $ a ->getId () < $ b ->getId () ? - 1 : 1 ;
90+ return $ a ->getId () <=> $ b ->getId ();
10291 }
103- return $ aTime < $ bTime ? - 1 : 1 ;
92+ return $ aTime <=> $ bTime ;
10493 });
10594 $ result [] = $ tmp2 ;
10695 }
@@ -117,7 +106,6 @@ private function groupShares(iterable $shares): array {
117106 * possible.
118107 *
119108 * @param iterable<IShare> $allShares
120- * @param IUser $user user
121109 * @return list<array{IShare, array<IShare>}> Tuple of [superShare, groupedShares]
122110 */
123111 private function buildSuperShares (iterable $ allShares , IUser $ user ): array {
@@ -205,8 +193,6 @@ private function mergeAttributes(
205193 * DB queries to retrieve the same information.
206194 *
207195 * @param array<IShare> $shares
208- * @param IShare $superShare
209- * @return void
210196 */
211197 private function combineNotes (
212198 array &$ shares ,
@@ -251,11 +237,8 @@ private function adjustTarget(
251237 }
252238 }
253239 /**
254- * @param string $userId
255240 * @param list<array{IShare, array<IShare>}> $superShares
256- * @param IStorageFactory $loader
257- * @param IUser $user
258- * @return array IMountPoint indexed by mount point
241+ * @return array<string, IMountPoint> indexed by mount point
259242 * @throws Exception
260243 */
261244 public function getMountsFromSuperShares (
@@ -264,13 +247,9 @@ public function getMountsFromSuperShares(
264247 IStorageFactory $ loader ,
265248 ): array {
266249 $ userId = $ user ->getUID ();
267- $ allMounts = $ this ->mountManager ->getAll ();
268250 $ mounts = [];
269- $ view = new View ('/ ' . $ userId . '/files ' );
270251 $ ownerViews = [];
271252 $ sharingDisabledForUser = $ this ->shareManager ->sharingDisabledForUser ($ userId );
272- /** @var CappedMemoryCache<bool> $folderExistCache */
273- $ foldersExistCache = new CappedMemoryCache ();
274253
275254 $ validShareCache = $ this ->cacheFactory ->createLocal ('share-valid-mountpoint-max ' );
276255 $ maxValidatedShare = $ validShareCache ->get ($ userId ) ?? 0 ;
@@ -293,7 +272,7 @@ public function getMountsFromSuperShares(
293272 }
294273 $ shareId = (int )$ parentShare ->getId ();
295274 $ mount = new SharedMount (
296- ' \OCA\Files_Sharing\ SharedStorage' ,
275+ SharedStorage::class ,
297276 [
298277 'user ' => $ userId ,
299278 // parent share
@@ -313,10 +292,9 @@ public function getMountsFromSuperShares(
313292 $ event = new ShareMountedEvent ($ mount );
314293 $ this ->eventDispatcher ->dispatchTyped ($ event );
315294
316- $ mounts [$ mount ->getMountPoint ()] = $ allMounts [ $ mount -> getMountPoint ()] = $ mount ;
295+ $ mounts [$ mount ->getMountPoint ()] = $ mount ;
317296 foreach ($ event ->getAdditionalMounts () as $ additionalMount ) {
318297 $ mounts [$ additionalMount ->getMountPoint ()] = $ additionalMount ;
319- $ allMounts [$ additionalMount ->getMountPoint ()] = $ additionalMount ;
320298 }
321299 } catch (Exception $ e ) {
322300 $ this ->logger ->error (
@@ -354,6 +332,7 @@ private function filterShares(iterable $shares, string $userId): iterable {
354332 }
355333 }
356334
335+ #[Override]
357336 public function getMountsForPath (
358337 string $ setupPathHint ,
359338 bool $ forChildren ,
@@ -394,8 +373,9 @@ public function getMountsForPath(
394373 }
395374
396375 /**
397- * @param iterable ...$iterables
398- * @return iterable
376+ * @template T
377+ * @param iterable<T> ...$iterables
378+ * @return iterable<T>
399379 */
400380 private function mergeIterables (...$ iterables ): iterable {
401381 foreach ($ iterables as $ iterable ) {
0 commit comments