Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/files/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@

/**
* @param \OCP\Files\Node[] $nodes
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
* @param int $depth The depth to traverse into the contents of each node
* @return list<array{id: int, basename: string, children: array, displayName?: string}>
*/
private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0): array {
private function getChildren(array $nodes, int $depth = 1, int $currentDepth = 0, ?string $mimeTypeFilter = null): array {
if ($currentDepth >= $depth) {
return [];
}
Expand All @@ -264,7 +266,7 @@
$entry = [
'id' => $node->getId(),
'basename' => $basename,
'children' => $this->getChildren($node->getDirectoryListing(), $depth, $currentDepth + 1),
'children' => $this->getChildren($node->getDirectoryListing($mimeTypeFilter), $depth, $currentDepth + 1),
];
$displayName = $node->getName();
if ($basename !== $displayName) {
Expand All @@ -281,7 +283,7 @@
* @param string $path The path relative to the user folder
* @param int $depth The depth of the tree
*
* @return JSONResponse<Http::STATUS_OK, FilesFolderTree, array{}>|JSONResponse<Http::STATUS_UNAUTHORIZED|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{message: string}, array{}>

Check failure on line 286 in apps/files/lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificReturnType

apps/files/lib/Controller/ApiController.php:286:13: MoreSpecificReturnType: The declared return type 'OCP\AppFramework\Http\JSONResponse<200|400|401|404, array{0?: array{basename: string, children: list<array<never, never>>, displayName?: string, id: int}, message?: string, ...<int<0, max>, array{basename: string, children: list<array<never, never>>, displayName?: string, id: int}>}, array<never, never>>' for OCA\Files\Controller\ApiController::getFolderTree is more specific than the inferred return type 'OCP\AppFramework\Http\JSONResponse<200|400|401|404, array{0?: array{basename: string, children: array<array-key, mixed>, displayName?: string, id: int}, message?: string, ...<int<0, max>, array{basename: string, children: array<array-key, mixed>, displayName?: string, id: int}>}, array<never, never>>' (see https://psalm.dev/070)
*
* 200: Folder tree returned successfully
* 400: Invalid folder path
Expand All @@ -308,8 +310,8 @@
'message' => $this->l10n->t('Invalid folder path'),
], Http::STATUS_BAD_REQUEST);
}
$nodes = $node->getDirectoryListing();
$tree = $this->getChildren($nodes, $depth);
$nodes = $node->getDirectoryListing('httpd/unix-directory');
$tree = $this->getChildren($nodes, $depth, 0, 'httpd/unix-directory');
} catch (NotFoundException $e) {
return new JSONResponse([
'message' => $this->l10n->t('Folder not found'),
Expand All @@ -318,7 +320,7 @@
$this->logger->error($th->getMessage(), ['exception' => $th]);
$tree = [];
}
return new JSONResponse($tree);

Check failure on line 323 in apps/files/lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

LessSpecificReturnStatement

apps/files/lib/Controller/ApiController.php:323:10: LessSpecificReturnStatement: The type 'OCP\AppFramework\Http\JSONResponse<200, list<array{basename: string, children: array<array-key, mixed>, displayName?: string, id: int}>, array<never, never>>' is more general than the declared return type 'OCP\AppFramework\Http\JSONResponse<200|400|401|404, array{0?: array{basename: string, children: list<array<never, never>>, displayName?: string, id: int}, message?: string, ...<int<0, max>, array{basename: string, children: list<array<never, never>>, displayName?: string, id: int}>}, array<never, never>>' for OCA\Files\Controller\ApiController::getFolderTree (see https://psalm.dev/129)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/lib/External/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function get($file) {
return $result;
}

public function getFolderContentsById($fileId) {
$results = parent::getFolderContentsById($fileId);
public function getFolderContentsById($fileId, ?string $mimeTypeFilter = null): array {
$results = parent::getFolderContentsById($fileId, $mimeTypeFilter);
foreach ($results as &$file) {
$file['displayname_owner'] = $this->cloudId->getDisplayId();
}
Expand Down
32 changes: 16 additions & 16 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IDBConnection;
use OCP\Util;
use Override;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -199,38 +200,37 @@ public static function cacheEntryFromData(array $data, IMimeTypeLoader $mimetype
return new CacheEntry($normalized);
}

/**
* get the metadata of all files stored in $folder
*
* @param string $folder
* @return ICacheEntry[]
*/
public function getFolderContents($folder) {
#[Override]
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null) {
$fileId = $this->getId($folder);
return $this->getFolderContentsById($fileId);
return $this->getFolderContentsById($fileId, $mimeTypeFilter);
}

/**
* get the metadata of all files stored in $folder
*
* @param int $fileId the file id of the folder
* @return ICacheEntry[]
*/
public function getFolderContentsById($fileId) {
#[Override]
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null) {
if ($fileId > -1) {
$query = $this->getQueryBuilder();
$query->selectFileCache()
->whereParent($fileId)
->whereStorageId($this->getNumericStorageId())
->orderBy('name', 'ASC');

if ($mimeTypeFilter !== null) {
$mimetype = $this->mimetypeLoader->getId($mimeTypeFilter);
if (str_contains($mimeTypeFilter, '/')) {
$query->andWhere($query->expr()->eq('mimetype', $query->createNamedParameter($mimetype)));
} else {
$query->andWhere($query->expr()->eq('mimepart', $query->createNamedParameter($mimetype)));
}
}

$metadataQuery = $query->selectMetadata();

$result = $query->executeQuery();
$files = $result->fetchAll();
$result->closeCursor();

return array_map(function (array $data) use ($metadataQuery) {
return array_map(function (array $data) use ($metadataQuery): ICacheEntry {
$data['metadata'] = $metadataQuery->extractMetadata($data)->asArray();
return self::cacheEntryFromData($data, $this->mimetypeLoader);
}, $files);
Expand Down
26 changes: 11 additions & 15 deletions lib/private/Files/Cache/FailedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@
* Storage placeholder to represent a missing precondition, storage unavailable
*/
class FailedCache implements ICache {
/** @var bool whether to show the failed storage in the ui */
private $visible;

/**
* FailedCache constructor.
*
* @param bool $visible
* @param bool $visible Whether to show the failed storage in the ui
*/
public function __construct($visible = true) {
$this->visible = $visible;
public function __construct(
private bool $visible = true,
) {
}


public function getNumericStorageId() {
public function getNumericStorageId(): int {
return -1;
}

public function get($file) {
public function get($file): false|ICacheEntry {
if ($file === '') {
return new CacheEntry([
'fileid' => -1,
Expand All @@ -51,11 +47,11 @@ public function get($file) {
}
}

public function getFolderContents($folder) {
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
return [];
}

public function getFolderContentsById($fileId) {
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null): array {
return [];
}

Expand All @@ -68,15 +64,15 @@ public function insert($file, array $data) {
public function update($id, array $data) {
}

public function getId($file) {
public function getId($file): int {
return -1;
}

public function getParentId($file) {
public function getParentId($file): int {
return -1;
}

public function inCache($file) {
public function inCache($file): bool {
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ public function get($file) {
* @param string $folder
* @return ICacheEntry[]
*/
public function getFolderContents($folder) {
public function getFolderContents(string $folder, ?string $mimeTypeFilter = null): array {
// can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
// and not the wrapped cache
$fileId = $this->getId($folder);
return $this->getFolderContentsById($fileId);
return $this->getFolderContentsById($fileId, $mimeTypeFilter);
}

/**
Expand All @@ -105,9 +105,9 @@ public function getFolderContents($folder) {
* @param int $fileId the file id of the folder
* @return array
*/
public function getFolderContentsById($fileId) {
$results = $this->getCache()->getFolderContentsById($fileId);
return array_map([$this, 'formatCacheEntry'], $results);
public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = null) {
$results = $this->getCache()->getFolderContentsById($fileId, $mimeTypeFilter);
return array_map($this->formatCacheEntry(...), $results);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,11 @@ public static function putFileInfo($path, $data) {
* get the content of a directory
*
* @param string $directory path under datadirectory
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
* @param ?non-empty-string $mimeTypeFilter limit returned content to this mimetype or mimepart
* @return \OC\Files\FileInfo[]
*/
public static function getDirectoryContent($directory, $mimetype_filter = '') {
return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
public static function getDirectoryContent($directory, ?string $mimeTypeFilter = null): array {
return self::$defaultInstance->getDirectoryContent($directory, $mimeTypeFilter);
}

/**
Expand Down
13 changes: 4 additions & 9 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,11 @@ public function isSubNode($node) {
return str_starts_with($node->getPath(), $this->path . '/');
}

/**
* get the content of this directory
*
* @return Node[]
* @throws \OCP\Files\NotFoundException
*/
public function getDirectoryListing() {
$folderContent = $this->view->getDirectoryContent($this->path, '', $this->getFileInfo(false));
#[Override]
public function getDirectoryListing(?string $mimetypeFilter = null): array {
$folderContent = $this->view->getDirectoryContent($this->path, $mimetypeFilter, $this->getFileInfo(false));

return array_map(function (FileInfo $info) {
return array_map(function (FileInfo $info): Node {
if ($info->getMimetype() === FileInfo::MIMETYPE_FOLDER) {
return new Folder($this->root, $this->view, $info->getPath(), $info, $this);
} else {
Expand Down
6 changes: 2 additions & 4 deletions lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,8 @@ public function isSubNode($node) {
return $this->__call(__FUNCTION__, func_get_args());
}

/**
* @inheritDoc
*/
public function getDirectoryListing() {
#[Override]
public function getDirectoryListing(?string $mimetypeFilter = null): array {
return $this->__call(__FUNCTION__, func_get_args());
}

Expand Down
4 changes: 3 additions & 1 deletion lib/private/Files/Node/NonExistingFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OC\Files\Node;

use OCP\Files\NotFoundException;
use Override;

class NonExistingFolder extends Folder {
/**
Expand Down Expand Up @@ -118,7 +119,8 @@ public function get($path) {
throw new NotFoundException();
}

public function getDirectoryListing() {
#[Override]
public function getDirectoryListing(?string $mimetypeFilter = null): never {
throw new NotFoundException();
}

Expand Down
Loading
Loading