3131use OCP \Files \Mount \IMountPoint ;
3232use OCP \Files \NotFoundException ;
3333use OCP \Files \ReservedWordException ;
34+ use OCP \Files \StorageInvalidException ;
35+ use OCP \Files \StorageNotAvailableException ;
3436use OCP \IUser ;
3537use OCP \IUserManager ;
3638use OCP \L10N \IFactory ;
@@ -1350,11 +1352,7 @@ public function hasUpdated($path, $time) {
13501352 return $ this ->basicOperation ('hasUpdated ' , $ path , [], $ time );
13511353 }
13521354
1353- /**
1354- * @param string $ownerId
1355- * @return IUser
1356- */
1357- private function getUserObjectForOwner (string $ ownerId ) {
1355+ private function getUserObjectForOwner (string $ ownerId ): IUser {
13581356 return new LazyUser ($ ownerId , $ this ->userManager );
13591357 }
13601358
@@ -1511,35 +1509,38 @@ public function getDirectoryContent($directory, $mimetype_filter = '', ?\OCP\Fil
15111509 $ contents = $ cache ->getFolderContentsById ($ folderId ); //TODO: mimetype_filter
15121510
15131511 $ sharingDisabled = \OCP \Util::isSharingDisabledForUser ();
1512+ $ permissionsMask = ~\OCP \Constants::PERMISSION_SHARE ;
1513+
1514+ $ files = [];
1515+ foreach ($ contents as $ content ) {
1516+ $ name = $ content ->getName ();
1517+ $ contentPath = $ content ->getPath ();
15141518
1515- $ fileNames = array_map (function (ICacheEntry $ content ) {
1516- return $ content ->getName ();
1517- }, $ contents );
1518- /**
1519- * @var \OC\Files\FileInfo[] $fileInfos
1520- */
1521- $ fileInfos = array_map (function (ICacheEntry $ content ) use ($ path , $ storage , $ mount , $ sharingDisabled ) {
15221519 if ($ sharingDisabled ) {
1523- $ content ['permissions ' ] = $ content ['permissions ' ] & ~\OCP \Constants::PERMISSION_SHARE ;
1524- }
1525- $ ownerId = $ storage ->getOwner ($ content ['path ' ]);
1526- if ($ ownerId !== false ) {
1527- $ owner = $ this ->getUserObjectForOwner ($ ownerId );
1528- } else {
1529- $ owner = null ;
1520+ $ content ['permissions ' ] = $ content ->getPermissions () & $ permissionsMask ;
15301521 }
1531- return new FileInfo ($ path . '/ ' . $ content ['name ' ], $ storage , $ content ['path ' ], $ content , $ mount , $ owner );
1532- }, $ contents );
1533- $ files = array_combine ($ fileNames , $ fileInfos );
1522+
1523+ $ ownerId = $ storage ->getOwner ($ contentPath );
1524+ $ owner = $ ownerId !== false
1525+ ? $ this ->getUserObjectForOwner ($ ownerId )
1526+ : null ;
1527+
1528+ $ files [$ name ] = new FileInfo (
1529+ $ path . '/ ' . $ name ,
1530+ $ storage ,
1531+ $ contentPath ,
1532+ $ content ,
1533+ $ mount ,
1534+ $ owner
1535+ );
1536+ }
15341537
15351538 //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
15361539 $ mounts = Filesystem::getMountManager ()->findIn ($ path );
15371540
15381541 // make sure nested mounts are sorted after their parent mounts
15391542 // otherwise doesn't propagate the etag across storage boundaries correctly
1540- usort ($ mounts , function (IMountPoint $ a , IMountPoint $ b ) {
1541- return $ a ->getMountPoint () <=> $ b ->getMountPoint ();
1542- });
1543+ usort ($ mounts , static fn (IMountPoint $ a , IMountPoint $ b ): int => $ a ->getMountPoint () <=> $ b ->getMountPoint ());
15431544
15441545 $ dirLength = strlen ($ path );
15451546 foreach ($ mounts as $ mount ) {
@@ -1553,9 +1554,7 @@ public function getDirectoryContent($directory, $mimetype_filter = '', ?\OCP\Fil
15531554 $ subScanner = $ subStorage ->getScanner ();
15541555 try {
15551556 $ subScanner ->scanFile ('' );
1556- } catch (\OCP \Files \StorageNotAvailableException $ e ) {
1557- continue ;
1558- } catch (\OCP \Files \StorageInvalidException $ e ) {
1557+ } catch (StorageNotAvailableException |StorageInvalidException ) {
15591558 continue ;
15601559 } catch (\Exception $ e ) {
15611560 // sometimes when the storage is not available it can be any exception
0 commit comments