Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: getNodeInfo type corrected, type check made strict, min/max type…
… converted, user check removed

Signed-off-by: yemkareems <[email protected]>
  • Loading branch information
yemkareems committed Jul 30, 2024
commit 8fc516c39a8559a0ad77bc2fc461684b8e3810b9
22 changes: 12 additions & 10 deletions apps/files/lib/Command/ListFiles.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -8,6 +9,7 @@

use OC\Core\Command\Base;
use OC\Core\Command\InterruptedException;
use OC\Files\Node\Node;
use OC\FilesMetadata\FilesMetadataManager;
use OC\ForbiddenException;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -49,13 +51,13 @@ protected function configure(): void {
->addOption("type", "", InputArgument::OPTIONAL, "Filter by type like application, image, video etc")
->addOption(
"minSize",
'0',
0,
InputArgument::OPTIONAL,
"Filter by min size"
)
->addOption(
"maxSize",
'0',
0,
InputArgument::OPTIONAL,
"Filter by max size"
)
Expand All @@ -68,7 +70,7 @@ protected function configure(): void {
->addOption("order", "ASC", InputArgument::OPTIONAL, "Order is either ASC or DESC");
}

private function getNodeInfo(File|Folder $node): array {
private function getNodeInfo(Node $node): array {
$nodeInfo = [
"name" => $node->getName(),
"size" => $node->getSize() . " bytes",
Expand Down Expand Up @@ -98,9 +100,11 @@ protected function listFiles(

$files = $userFolder->getDirectoryListing();
foreach ($files as $file) {
/** @var Node $fileNode */
$fileNode = $file;
$includeType = $includeMin = $includeMax = true;
$nodeInfo = $this->getNodeInfo($file);
if ($type != "" && $type != $nodeInfo['type']) {
$nodeInfo = $this->getNodeInfo($fileNode);
if ($type !== "" && $type !== $nodeInfo['type']) {
$includeType = false;
}
if ($minSize > 0) {
Expand Down Expand Up @@ -147,16 +151,14 @@ protected function execute(
OutputInterface $output
): int {
$inputPath = $input->getArgument("path");
$user = '';
if ($inputPath) {
$inputPath = ltrim($inputPath, "path=");
[, $user] = explode("/", rtrim($inputPath, "/").'/', 4);
}

$this->initTools($output);

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

if ($this->userManager->userExists($user)) {
Expand All @@ -168,8 +170,8 @@ protected function execute(
$path,
$output,
$input->getOption("type"),
$input->getOption("minSize"),
$input->getOption("maxSize")
(int) $input->getOption("minSize"),
(int) $input->getOption("maxSize")
);
} else {
$output->writeln(
Expand Down