@@ -1180,7 +1180,7 @@ private function basicOperation($operation, $path, $hooks = [], $extraParam = nu
11801180 throw $ e ;
11811181 }
11821182
1183- if ($ result && in_array ('delete ' , $ hooks ) and $ result ) {
1183+ if ($ result && in_array ('delete ' , $ hooks )) {
11841184 $ this ->removeUpdate ($ storage , $ internalPath );
11851185 }
11861186 if ($ result && in_array ('write ' , $ hooks , true ) && $ operation !== 'fopen ' && $ operation !== 'touch ' ) {
@@ -1436,124 +1436,122 @@ public function getDirectoryContent($directory, $mimetype_filter = '') {
14361436 if (!Filesystem::isValidPath ($ directory )) {
14371437 return [];
14381438 }
1439+
14391440 $ path = $ this ->getAbsolutePath ($ directory );
14401441 $ path = Filesystem::normalizePath ($ path );
14411442 $ mount = $ this ->getMount ($ directory );
1442- if (!$ mount ) {
1443- return [];
1444- }
14451443 $ storage = $ mount ->getStorage ();
14461444 $ internalPath = $ mount ->getInternalPath ($ path );
1447- if ($ storage ) {
1448- $ cache = $ storage -> getCache ( $ internalPath ) ;
1449- $ user = \OC_User:: getUser ();
1445+ if (! $ storage ) {
1446+ return [] ;
1447+ }
14501448
1451- $ data = $ this ->getCacheEntry ($ storage , $ internalPath , $ directory );
1449+ $ cache = $ storage ->getCache ($ internalPath );
1450+ $ user = \OC_User::getUser ();
14521451
1453- if (!$ data instanceof ICacheEntry || !isset ($ data ['fileid ' ]) || !($ data ->getPermissions () && Constants::PERMISSION_READ )) {
1454- return [];
1455- }
1452+ $ data = $ this ->getCacheEntry ($ storage , $ internalPath , $ directory );
14561453
1457- $ folderId = $ data ['fileid ' ];
1458- $ contents = $ cache ->getFolderContentsById ($ folderId ); //TODO: mimetype_filter
1454+ if (!$ data instanceof ICacheEntry || !isset ($ data ['fileid ' ]) || !($ data ->getPermissions () & Constants::PERMISSION_READ )) {
1455+ return [];
1456+ }
14591457
1460- $ sharingDisabled = \OCP \Util::isSharingDisabledForUser ();
1458+ $ folderId = $ data ['fileid ' ];
1459+ $ contents = $ cache ->getFolderContentsById ($ folderId ); //TODO: mimetype_filter
14611460
1462- $ fileNames = array_map (function (ICacheEntry $ content ) {
1463- return $ content ->getName ();
1464- }, $ contents );
1465- /**
1466- * @var \OC\Files\FileInfo[] $fileInfos
1467- */
1468- $ fileInfos = array_map (function (ICacheEntry $ content ) use ($ path , $ storage , $ mount , $ sharingDisabled ) {
1469- if ($ sharingDisabled ) {
1470- $ content ['permissions ' ] = $ content ['permissions ' ] & ~\OCP \Constants::PERMISSION_SHARE ;
1471- }
1472- $ owner = $ this ->getUserObjectForOwner ($ storage ->getOwner ($ content ['path ' ]));
1473- return new FileInfo ($ path . '/ ' . $ content ['name ' ], $ storage , $ content ['path ' ], $ content , $ mount , $ owner );
1474- }, $ contents );
1475- $ files = array_combine ($ fileNames , $ fileInfos );
1476-
1477- //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
1478- $ mounts = Filesystem::getMountManager ()->findIn ($ path );
1479- $ dirLength = strlen ($ path );
1480- foreach ($ mounts as $ mount ) {
1481- $ mountPoint = $ mount ->getMountPoint ();
1482- $ subStorage = $ mount ->getStorage ();
1483- if ($ subStorage ) {
1484- $ subCache = $ subStorage ->getCache ('' );
1461+ $ sharingDisabled = \OCP \Util::isSharingDisabledForUser ();
14851462
1486- $ rootEntry = $ subCache ->get ('' );
1487- if (!$ rootEntry ) {
1488- $ subScanner = $ subStorage ->getScanner ();
1489- try {
1490- $ subScanner ->scanFile ('' );
1491- } catch (\OCP \Files \StorageNotAvailableException $ e ) {
1492- continue ;
1493- } catch (\OCP \Files \StorageInvalidException $ e ) {
1494- continue ;
1495- } catch (\Exception $ e ) {
1496- // sometimes when the storage is not available it can be any exception
1497- \OC ::$ server ->getLogger ()->logException ($ e , [
1498- 'message ' => 'Exception while scanning storage " ' . $ subStorage ->getId () . '" ' ,
1499- 'level ' => ILogger::ERROR ,
1500- 'app ' => 'lib ' ,
1501- ]);
1502- continue ;
1503- }
1504- $ rootEntry = $ subCache ->get ('' );
1463+ $ fileNames = array_map (function (ICacheEntry $ content ) {
1464+ return $ content ->getName ();
1465+ }, $ contents );
1466+ /**
1467+ * @var \OC\Files\FileInfo[] $fileInfos
1468+ */
1469+ $ fileInfos = array_map (function (ICacheEntry $ content ) use ($ path , $ storage , $ mount , $ sharingDisabled ) {
1470+ if ($ sharingDisabled ) {
1471+ $ content ['permissions ' ] = $ content ['permissions ' ] & ~\OCP \Constants::PERMISSION_SHARE ;
1472+ }
1473+ $ owner = $ this ->getUserObjectForOwner ($ storage ->getOwner ($ content ['path ' ]));
1474+ return new FileInfo ($ path . '/ ' . $ content ['name ' ], $ storage , $ content ['path ' ], $ content , $ mount , $ owner );
1475+ }, $ contents );
1476+ $ files = array_combine ($ fileNames , $ fileInfos );
1477+
1478+ //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
1479+ $ mounts = Filesystem::getMountManager ()->findIn ($ path );
1480+ $ dirLength = strlen ($ path );
1481+ foreach ($ mounts as $ mount ) {
1482+ $ mountPoint = $ mount ->getMountPoint ();
1483+ $ subStorage = $ mount ->getStorage ();
1484+ if ($ subStorage ) {
1485+ $ subCache = $ subStorage ->getCache ('' );
1486+
1487+ $ rootEntry = $ subCache ->get ('' );
1488+ if (!$ rootEntry ) {
1489+ $ subScanner = $ subStorage ->getScanner ();
1490+ try {
1491+ $ subScanner ->scanFile ('' );
1492+ } catch (\OCP \Files \StorageNotAvailableException $ e ) {
1493+ continue ;
1494+ } catch (\OCP \Files \StorageInvalidException $ e ) {
1495+ continue ;
1496+ } catch (\Exception $ e ) {
1497+ // sometimes when the storage is not available it can be any exception
1498+ \OC ::$ server ->getLogger ()->logException ($ e , [
1499+ 'message ' => 'Exception while scanning storage " ' . $ subStorage ->getId () . '" ' ,
1500+ 'level ' => ILogger::ERROR ,
1501+ 'app ' => 'lib ' ,
1502+ ]);
1503+ continue ;
15051504 }
1505+ $ rootEntry = $ subCache ->get ('' );
1506+ }
15061507
1507- if ($ rootEntry && ($ rootEntry ->getPermissions () && Constants::PERMISSION_READ )) {
1508- $ relativePath = trim (substr ($ mountPoint , $ dirLength ), '/ ' );
1509- if ($ pos = strpos ($ relativePath , '/ ' )) {
1510- //mountpoint inside subfolder add size to the correct folder
1511- $ entryName = substr ($ relativePath , 0 , $ pos );
1512- foreach ($ files as &$ entry ) {
1513- if ($ entry ->getName () === $ entryName ) {
1514- $ entry ->addSubEntry ($ rootEntry , $ mountPoint );
1515- }
1508+ if ($ rootEntry && ($ rootEntry ->getPermissions () & Constants::PERMISSION_READ )) {
1509+ $ relativePath = trim (substr ($ mountPoint , $ dirLength ), '/ ' );
1510+ if ($ pos = strpos ($ relativePath , '/ ' )) {
1511+ //mountpoint inside subfolder add size to the correct folder
1512+ $ entryName = substr ($ relativePath , 0 , $ pos );
1513+ foreach ($ files as &$ entry ) {
1514+ if ($ entry ->getName () === $ entryName ) {
1515+ $ entry ->addSubEntry ($ rootEntry , $ mountPoint );
15161516 }
1517- } else { //mountpoint in this folder, add an entry for it
1518- $ rootEntry ['name ' ] = $ relativePath ;
1519- $ rootEntry ['type ' ] = $ rootEntry ['mimetype ' ] === 'httpd/unix-directory ' ? 'dir ' : 'file ' ;
1520- $ permissions = $ rootEntry ['permissions ' ];
1521- // do not allow renaming/deleting the mount point if they are not shared files/folders
1522- // for shared files/folders we use the permissions given by the owner
1523- if ($ mount instanceof MoveableMount) {
1524- $ rootEntry ['permissions ' ] = $ permissions | \OCP \Constants::PERMISSION_UPDATE | \OCP \Constants::PERMISSION_DELETE ;
1525- } else {
1526- $ rootEntry ['permissions ' ] = $ permissions & (\OCP \Constants::PERMISSION_ALL - (\OCP \Constants::PERMISSION_UPDATE | \OCP \Constants::PERMISSION_DELETE ));
1527- }
1528-
1529- $ rootEntry ['path ' ] = substr (Filesystem::normalizePath ($ path . '/ ' . $ rootEntry ['name ' ]), strlen ($ user ) + 2 ); // full path without /$user/
1517+ }
1518+ } else { //mountpoint in this folder, add an entry for it
1519+ $ rootEntry ['name ' ] = $ relativePath ;
1520+ $ rootEntry ['type ' ] = $ rootEntry ['mimetype ' ] === 'httpd/unix-directory ' ? 'dir ' : 'file ' ;
1521+ $ permissions = $ rootEntry ['permissions ' ];
1522+ // do not allow renaming/deleting the mount point if they are not shared files/folders
1523+ // for shared files/folders we use the permissions given by the owner
1524+ if ($ mount instanceof MoveableMount) {
1525+ $ rootEntry ['permissions ' ] = $ permissions | \OCP \Constants::PERMISSION_UPDATE | \OCP \Constants::PERMISSION_DELETE ;
1526+ } else {
1527+ $ rootEntry ['permissions ' ] = $ permissions & (\OCP \Constants::PERMISSION_ALL - (\OCP \Constants::PERMISSION_UPDATE | \OCP \Constants::PERMISSION_DELETE ));
1528+ }
15301529
1531- // if sharing was disabled for the user we remove the share permissions
1532- if (\OCP \Util::isSharingDisabledForUser ()) {
1533- $ rootEntry ['permissions ' ] = $ rootEntry ['permissions ' ] & ~\OCP \Constants::PERMISSION_SHARE ;
1534- }
1530+ $ rootEntry ['path ' ] = substr (Filesystem::normalizePath ($ path . '/ ' . $ rootEntry ['name ' ]), strlen ($ user ) + 2 ); // full path without /$user/
15351531
1536- $ owner = $ this ->getUserObjectForOwner ($ subStorage ->getOwner ('' ));
1537- $ files [$ rootEntry ->getName ()] = new FileInfo ($ path . '/ ' . $ rootEntry ['name ' ], $ subStorage , '' , $ rootEntry , $ mount , $ owner );
1532+ // if sharing was disabled for the user we remove the share permissions
1533+ if (\OCP \Util::isSharingDisabledForUser ()) {
1534+ $ rootEntry ['permissions ' ] = $ rootEntry ['permissions ' ] & ~\OCP \Constants::PERMISSION_SHARE ;
15381535 }
1539- }
1540- }
1541- }
15421536
1543- if ($ mimetype_filter ) {
1544- $ files = array_filter ($ files , function (FileInfo $ file ) use ($ mimetype_filter ) {
1545- if (strpos ($ mimetype_filter , '/ ' )) {
1546- return $ file ->getMimetype () === $ mimetype_filter ;
1547- } else {
1548- return $ file ->getMimePart () === $ mimetype_filter ;
1537+ $ owner = $ this ->getUserObjectForOwner ($ subStorage ->getOwner ('' ));
1538+ $ files [$ rootEntry ->getName ()] = new FileInfo ($ path . '/ ' . $ rootEntry ['name ' ], $ subStorage , '' , $ rootEntry , $ mount , $ owner );
15491539 }
1550- });
1540+ }
15511541 }
1542+ }
15521543
1553- return array_values ($ files );
1554- } else {
1555- return [];
1544+ if ($ mimetype_filter ) {
1545+ $ files = array_filter ($ files , function (FileInfo $ file ) use ($ mimetype_filter ) {
1546+ if (strpos ($ mimetype_filter , '/ ' )) {
1547+ return $ file ->getMimetype () === $ mimetype_filter ;
1548+ } else {
1549+ return $ file ->getMimePart () === $ mimetype_filter ;
1550+ }
1551+ });
15561552 }
1553+
1554+ return array_values ($ files );
15571555 }
15581556
15591557 /**
0 commit comments