Skip to content

Commit 86dfbfc

Browse files
committed
fix: getNodeInfo type corrected, type check made strict, min/max type converted, user check removed
Signed-off-by: yemkareems <[email protected]>
1 parent f71c5aa commit 86dfbfc

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

apps/files/lib/Command/ListFiles.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,7 @@
89

910
use OC\Core\Command\Base;
1011
use OC\Core\Command\InterruptedException;
12+
use OC\Files\Node\Node;
1113
use OC\FilesMetadata\FilesMetadataManager;
1214
use OC\ForbiddenException;
1315
use OCP\EventDispatcher\IEventDispatcher;
@@ -49,13 +51,13 @@ protected function configure(): void {
4951
->addOption("type", "", InputArgument::OPTIONAL, "Filter by type like application, image, video etc")
5052
->addOption(
5153
"minSize",
52-
'0',
54+
0,
5355
InputArgument::OPTIONAL,
5456
"Filter by min size"
5557
)
5658
->addOption(
5759
"maxSize",
58-
'0',
60+
0,
5961
InputArgument::OPTIONAL,
6062
"Filter by max size"
6163
)
@@ -68,7 +70,7 @@ protected function configure(): void {
6870
->addOption("order", "ASC", InputArgument::OPTIONAL, "Order is either ASC or DESC");
6971
}
7072

71-
private function getNodeInfo(File|Folder $node): array {
73+
private function getNodeInfo(Node $node): array {
7274
$nodeInfo = [
7375
"name" => $node->getName(),
7476
"size" => $node->getSize() . " bytes",
@@ -98,9 +100,11 @@ protected function listFiles(
98100

99101
$files = $userFolder->getDirectoryListing();
100102
foreach ($files as $file) {
103+
/** @var Node $fileNode */
104+
$fileNode = $file;
101105
$includeType = $includeMin = $includeMax = true;
102-
$nodeInfo = $this->getNodeInfo($file);
103-
if ($type != "" && $type != $nodeInfo['type']) {
106+
$nodeInfo = $this->getNodeInfo($fileNode);
107+
if ($type !== "" && $type !== $nodeInfo['type']) {
104108
$includeType = false;
105109
}
106110
if ($minSize > 0) {
@@ -147,16 +151,14 @@ protected function execute(
147151
OutputInterface $output
148152
): int {
149153
$inputPath = $input->getArgument("path");
154+
$user = '';
150155
if ($inputPath) {
151156
$inputPath = ltrim($inputPath, "path=");
152157
[, $user] = explode("/", rtrim($inputPath, "/").'/', 4);
153158
}
154159

155160
$this->initTools($output);
156161

157-
if (is_object($user)) {
158-
$user = $user->getUID();
159-
}
160162
$path = $inputPath ?: "/" . $user;
161163

162164
if ($this->userManager->userExists($user)) {
@@ -168,8 +170,8 @@ protected function execute(
168170
$path,
169171
$output,
170172
$input->getOption("type"),
171-
$input->getOption("minSize"),
172-
$input->getOption("maxSize")
173+
(int) $input->getOption("minSize"),
174+
(int) $input->getOption("maxSize")
173175
);
174176
} else {
175177
$output->writeln(

0 commit comments

Comments
 (0)