mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Exit early if $storage is falsy in View::getDirectoryContent
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
916fbe81c6
commit
d36a1a7bf6
1 changed files with 109 additions and 111 deletions
|
|
@ -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();
|
||||
|
||||
$data = $this->getCacheEntry($storage, $internalPath, $directory);
|
||||
|
||||
if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() & Constants::PERMISSION_READ)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$folderId = $data['fileid'];
|
||||
$contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
|
||||
|
||||
$sharingDisabled = \OCP\Util::isSharingDisabledForUser();
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
} 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/
|
||||
|
||||
// if sharing was disabled for the user we remove the share permissions
|
||||
if (\OCP\Util::isSharingDisabledForUser()) {
|
||||
$rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
|
||||
}
|
||||
|
||||
$owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
|
||||
$files[$rootEntry->getName()] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
if (!$storage) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cache = $storage->getCache($internalPath);
|
||||
$user = \OC_User::getUser();
|
||||
|
||||
$data = $this->getCacheEntry($storage, $internalPath, $directory);
|
||||
|
||||
if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() & Constants::PERMISSION_READ)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$folderId = $data['fileid'];
|
||||
$contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
|
||||
|
||||
$sharingDisabled = \OCP\Util::isSharingDisabledForUser();
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
} 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/
|
||||
|
||||
// if sharing was disabled for the user we remove the share permissions
|
||||
if (\OCP\Util::isSharingDisabledForUser()) {
|
||||
$rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
|
||||
}
|
||||
|
||||
$owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
|
||||
$files[$rootEntry->getName()] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue