Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-04-05 11:35:53 +0300
committerCôme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com>2022-04-05 16:58:49 +0300
commitd36a1a7bf6bfd692f97132e586ced609d91fc65c (patch)
treee7d2564f228a5f46c9808d8cb28dda3b9b09ce3b /lib/private/Files/View.php
parent916fbe81c6baabb59e7d5444cbc04bf696f679df (diff)
Exit early if $storage is falsy in View::getDirectoryContent
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/Files/View.php')
-rw-r--r--lib/private/Files/View.php190
1 files changed, 94 insertions, 96 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 4a9c6fd3bcb..8f3a108bc2c 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1436,124 +1436,122 @@ class View {
if (!Filesystem::isValidPath($directory)) {
return [];
}
+
$path = $this->getAbsolutePath($directory);
$path = Filesystem::normalizePath($path);
$mount = $this->getMount($directory);
- if (!$mount) {
- return [];
- }
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($path);
- if ($storage) {
- $cache = $storage->getCache($internalPath);
- $user = \OC_User::getUser();
+ if (!$storage) {
+ return [];
+ }
- $data = $this->getCacheEntry($storage, $internalPath, $directory);
+ $cache = $storage->getCache($internalPath);
+ $user = \OC_User::getUser();
- if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() & Constants::PERMISSION_READ)) {
- return [];
- }
+ $data = $this->getCacheEntry($storage, $internalPath, $directory);
- $folderId = $data['fileid'];
- $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
+ if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() & Constants::PERMISSION_READ)) {
+ return [];
+ }
- $sharingDisabled = \OCP\Util::isSharingDisabledForUser();
+ $folderId = $data['fileid'];
+ $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
- $fileNames = array_map(function (ICacheEntry $content) {
- return $content->getName();
- }, $contents);
- /**
- * @var \OC\Files\FileInfo[] $fileInfos
- */
- $fileInfos = array_map(function (ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) {
- if ($sharingDisabled) {
- $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
- }
- $owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
- return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
- }, $contents);
- $files = array_combine($fileNames, $fileInfos);
-
- //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
- $mounts = Filesystem::getMountManager()->findIn($path);
- $dirLength = strlen($path);
- foreach ($mounts as $mount) {
- $mountPoint = $mount->getMountPoint();
- $subStorage = $mount->getStorage();
- if ($subStorage) {
- $subCache = $subStorage->getCache('');
+ $sharingDisabled = \OCP\Util::isSharingDisabledForUser();
- $rootEntry = $subCache->get('');
- if (!$rootEntry) {
- $subScanner = $subStorage->getScanner();
- try {
- $subScanner->scanFile('');
- } catch (\OCP\Files\StorageNotAvailableException $e) {
- continue;
- } catch (\OCP\Files\StorageInvalidException $e) {
- continue;
- } catch (\Exception $e) {
- // sometimes when the storage is not available it can be any exception
- \OC::$server->getLogger()->logException($e, [
- 'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"',
- 'level' => ILogger::ERROR,
- 'app' => 'lib',
- ]);
- continue;
- }
- $rootEntry = $subCache->get('');
+ $fileNames = array_map(function (ICacheEntry $content) {
+ return $content->getName();
+ }, $contents);
+ /**
+ * @var \OC\Files\FileInfo[] $fileInfos
+ */
+ $fileInfos = array_map(function (ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) {
+ if ($sharingDisabled) {
+ $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
+ }
+ $owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
+ return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
+ }, $contents);
+ $files = array_combine($fileNames, $fileInfos);
+
+ //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
+ $mounts = Filesystem::getMountManager()->findIn($path);
+ $dirLength = strlen($path);
+ foreach ($mounts as $mount) {
+ $mountPoint = $mount->getMountPoint();
+ $subStorage = $mount->getStorage();
+ if ($subStorage) {
+ $subCache = $subStorage->getCache('');
+
+ $rootEntry = $subCache->get('');
+ if (!$rootEntry) {
+ $subScanner = $subStorage->getScanner();
+ try {
+ $subScanner->scanFile('');
+ } catch (\OCP\Files\StorageNotAvailableException $e) {
+ continue;
+ } catch (\OCP\Files\StorageInvalidException $e) {
+ continue;
+ } catch (\Exception $e) {
+ // sometimes when the storage is not available it can be any exception
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"',
+ 'level' => ILogger::ERROR,
+ 'app' => 'lib',
+ ]);
+ continue;
}
+ $rootEntry = $subCache->get('');
+ }
- if ($rootEntry && ($rootEntry->getPermissions() & Constants::PERMISSION_READ)) {
- $relativePath = trim(substr($mountPoint, $dirLength), '/');
- if ($pos = strpos($relativePath, '/')) {
- //mountpoint inside subfolder add size to the correct folder
- $entryName = substr($relativePath, 0, $pos);
- foreach ($files as &$entry) {
- if ($entry->getName() === $entryName) {
- $entry->addSubEntry($rootEntry, $mountPoint);
- }
+ if ($rootEntry && ($rootEntry->getPermissions() & Constants::PERMISSION_READ)) {
+ $relativePath = trim(substr($mountPoint, $dirLength), '/');
+ if ($pos = strpos($relativePath, '/')) {
+ //mountpoint inside subfolder add size to the correct folder
+ $entryName = substr($relativePath, 0, $pos);
+ foreach ($files as &$entry) {
+ if ($entry->getName() === $entryName) {
+ $entry->addSubEntry($rootEntry, $mountPoint);
}
- } else { //mountpoint in this folder, add an entry for it
- $rootEntry['name'] = $relativePath;
- $rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
- $permissions = $rootEntry['permissions'];
- // do not allow renaming/deleting the mount point if they are not shared files/folders
- // for shared files/folders we use the permissions given by the owner
- if ($mount instanceof MoveableMount) {
- $rootEntry['permissions'] = $permissions | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
- } else {
- $rootEntry['permissions'] = $permissions & (\OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE));
- }
-
- $rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
+ }
+ } else { //mountpoint in this folder, add an entry for it
+ $rootEntry['name'] = $relativePath;
+ $rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
+ $permissions = $rootEntry['permissions'];
+ // do not allow renaming/deleting the mount point if they are not shared files/folders
+ // for shared files/folders we use the permissions given by the owner
+ if ($mount instanceof MoveableMount) {
+ $rootEntry['permissions'] = $permissions | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
+ } else {
+ $rootEntry['permissions'] = $permissions & (\OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE));
+ }
- // if sharing was disabled for the user we remove the share permissions
- if (\OCP\Util::isSharingDisabledForUser()) {
- $rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
- }
+ $rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
- $owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
- $files[$rootEntry->getName()] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
+ // if sharing was disabled for the user we remove the share permissions
+ if (\OCP\Util::isSharingDisabledForUser()) {
+ $rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
}
- }
- }
- }
- if ($mimetype_filter) {
- $files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
- if (strpos($mimetype_filter, '/')) {
- return $file->getMimetype() === $mimetype_filter;
- } else {
- return $file->getMimePart() === $mimetype_filter;
+ $owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
+ $files[$rootEntry->getName()] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
}
- });
+ }
}
+ }
- return array_values($files);
- } else {
- return [];
+ if ($mimetype_filter) {
+ $files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
+ if (strpos($mimetype_filter, '/')) {
+ return $file->getMimetype() === $mimetype_filter;
+ } else {
+ return $file->getMimePart() === $mimetype_filter;
+ }
+ });
}
+
+ return array_values($files);
}
/**