aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryemkareems <yemkareems@gmail.com>2024-07-09 14:31:47 +0530
committeryemkareems <yemkareems@gmail.com>2024-07-30 10:01:15 +0530
commite4a7de92df0058890e7861c399831723d88462e0 (patch)
tree62228faf5314007e43031cd12f8ac0fe80d7347c
parent66fa88fad2cf41f55243a4ecf664d2cccd576c5b (diff)
downloadnextcloud-server-e4a7de92df0058890e7861c399831723d88462e0.tar.gz
nextcloud-server-e4a7de92df0058890e7861c399831723d88462e0.zip
fix: humanFileSize added for size, type strict check removed as it is breaking the listing, inputPath check removed as path is mandatory, sorting done only when sort param is there, writeTableInOutputFormat done
Signed-off-by: yemkareems <yemkareems@gmail.com>
-rw-r--r--apps/files/lib/Command/ListFiles.php72
1 files changed, 30 insertions, 42 deletions
diff --git a/apps/files/lib/Command/ListFiles.php b/apps/files/lib/Command/ListFiles.php
index b0c7c50ddde..4420ca1de92 100644
--- a/apps/files/lib/Command/ListFiles.php
+++ b/apps/files/lib/Command/ListFiles.php
@@ -74,7 +74,7 @@ class ListFiles extends Base {
private function getNodeInfo(Node $node): array {
$nodeInfo = [
"name" => $node->getName(),
- "size" => $node->getSize() . " bytes",
+ "size" => \OCP\Util::humanFileSize($node->getSize()),
"perm" => $node->getPermissions(),
"owner" => $node->getOwner()?->getDisplayName(),
"created-at" => $node->getCreationTime(),
@@ -105,7 +105,7 @@ class ListFiles extends Base {
$fileNode = $file;
$includeType = $includeMin = $includeMax = true;
$nodeInfo = $this->getNodeInfo($fileNode);
- if ($type !== "" && $type !== $nodeInfo['type']) {
+ if ($type != "" && $type !== $nodeInfo['type']) {
$includeType = false;
}
if ($minSize > 0) {
@@ -152,11 +152,8 @@ class ListFiles extends Base {
OutputInterface $output
): int {
$inputPath = $input->getArgument("path");
- $user = '';
- if ($inputPath) {
- $inputPath = ltrim($inputPath, "path=");
- [, $user] = explode("/", rtrim($inputPath, "/").'/', 4);
- }
+ $inputPath = ltrim($inputPath, "path=");
+ [, $user] = explode("/", rtrim($inputPath, "/").'/', 4);
$this->initTools($output);
@@ -245,56 +242,47 @@ class ListFiles extends Base {
InputInterface $input,
OutputInterface $output
): void {
- $headers = [
- "Permission",
- "Size",
- "Owner",
- "Created at",
- "Filename",
- "Type",
- ];
$rows = [];
$fileInfo = $this->fileInfo[0] ?? [];
$sortKey = array_key_exists($input->getOption("sort"), $fileInfo)
? $input->getOption("sort")
- : "name";
+ : "";
$order = $input->getOption("order") == "ASC" ? SORT_ASC : SORT_DESC;
$fileArr = array_column($this->fileInfo, $sortKey);
$dirArr = array_column($this->dirInfo, $sortKey);
- array_multisort(
- $fileArr,
- $order,
- $this->fileInfo
- );
- array_multisort(
- $dirArr,
- $order,
- $this->dirInfo
- );
-
+ if($sortKey != '') {
+ array_multisort(
+ $fileArr,
+ $order,
+ $this->fileInfo
+ );
+ array_multisort(
+ $dirArr,
+ $order,
+ $this->dirInfo
+ );
+ }
foreach ($this->fileInfo as $k => $item) {
$rows[$k] = [
- $item["perm"],
- $item["size"],
- $item["owner"],
- $item["created-at"],
- $item["name"],
- $item["type"],
+ "Permission" => $item["perm"],
+ "Size" => $item["size"],
+ "Owner" => $item["owner"],
+ "Created at" => $item["created-at"],
+ "Filename" => $item["name"],
+ "Type" => $item["type"],
];
}
foreach ($this->dirInfo as $k => $item) {
$rows[] = [
- $item["perm"],
- $item["size"],
- $item["owner"],
- $item["created-at"],
- $item["name"],
- $item["type"],
+ "Permission" => $item["perm"],
+ "Size" => $item["size"],
+ "Owner" => $item["owner"],
+ "Created at" => $item["created-at"],
+ "Filename" => $item["name"],
+ "Type" => $item["type"],
];
}
- $table = new Table($output);
- $table->setHeaders($headers)->setRows($rows);
- $table->render();
+ $this->writeTableInOutputFormat($input, $output, $rows);
}
}