Skip to content

Commit 90e0071

Browse files
committed
add option to list all files instead of limiting
Signed-off-by: Robin Appelman <[email protected]>
1 parent 05eb9f8 commit 90e0071

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

core/Command/Info/File.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
use OC\Files\ObjectStore\ObjectStoreStorage;
88
use OCA\Files_External\Config\ExternalMountPoint;
99
use OCA\GroupFolders\Mount\GroupMountPoint;
10-
use OCP\Files\Config\IUserMountCache;
1110
use OCP\Files\Folder;
1211
use OCP\Files\IHomeStorage;
13-
use OCP\Files\IRootFolder;
1412
use OCP\Files\Mount\IMountPoint;
1513
use OCP\Files\Node;
1614
use OCP\Files\NotFoundException;

core/Command/Info/FileUtils.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
namespace OC\Core\Command\Info;
2525

26-
2726
use OC\Files\SetupManager;
2827
use OCA\Circles\MountManager\CircleMount;
2928
use OCA\Files_External\Config\ExternalMountPoint;
@@ -196,7 +195,8 @@ public function outputLargeFilesTree(
196195
OutputInterface $output,
197196
Folder $node,
198197
string $prefix,
199-
array &$sizeLimits
198+
array &$sizeLimits,
199+
bool $all,
200200
): int {
201201
/**
202202
* Algorithm to print the N largest items in a folder without requiring to query or sort the entire three
@@ -221,25 +221,31 @@ public function outputLargeFilesTree(
221221
return $b->getSize() <=> $a->getSize();
222222
});
223223
foreach ($children as $i => $child) {
224-
if (count($sizeLimits) === 0 || $child->getSize() < $sizeLimits[0]) {
225-
return $count;
224+
if (!$all) {
225+
if (count($sizeLimits) === 0 || $child->getSize() < $sizeLimits[0]) {
226+
return $count;
227+
}
228+
array_shift($sizeLimits);
226229
}
227-
array_shift($sizeLimits);
228230
$count += 1;
229231

230232
/** @var Node $child */
231233
$output->writeln("$prefix- " . $child->getName() . ": <info>" . Util::humanFileSize($child->getSize()) . "</info>");
232234
if ($child instanceof Folder) {
233235
$recurseSizeLimits = $sizeLimits;
234-
for ($j = 0; $j < count($recurseSizeLimits); $j++) {
235-
$nextChildSize = (int)$children[$i + $j + 1]?->getSize();
236-
if ($nextChildSize > $recurseSizeLimits[0]) {
237-
array_shift($recurseSizeLimits);
238-
$recurseSizeLimits[] = $nextChildSize;
236+
if (!$all) {
237+
for ($j = 0; $j < count($recurseSizeLimits); $j++) {
238+
if (isset($children[$i + $j + 1])) {
239+
$nextChildSize = $children[$i + $j + 1]->getSize();
240+
if ($nextChildSize > $recurseSizeLimits[0]) {
241+
array_shift($recurseSizeLimits);
242+
$recurseSizeLimits[] = $nextChildSize;
243+
}
244+
}
239245
}
246+
sort($recurseSizeLimits);
240247
}
241-
sort($recurseSizeLimits);
242-
$recurseCount = $this->outputLargeFilesTree($output, $child, $prefix . " ", $recurseSizeLimits);
248+
$recurseCount = $this->outputLargeFilesTree($output, $child, $prefix . " ", $recurseSizeLimits, $all);
243249
$sizeLimits = array_slice($sizeLimits, $recurseCount);
244250
$count += $recurseCount;
245251
}

core/Command/Info/Space.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
namespace OC\Core\Command\Info;
2525

26-
2726
use OCP\Files\Folder;
2827
use OCP\Util;
2928
use Symfony\Component\Console\Command\Command;
@@ -45,23 +44,24 @@ protected function configure(): void {
4544
->setName('info:file:space')
4645
->setDescription('Summarize space usage of specified folder')
4746
->addArgument('file', InputArgument::REQUIRED, "File id or path")
48-
->addOption('count', 'c', InputOption::VALUE_REQUIRED, "Number of items to display", 25);
47+
->addOption('count', 'c', InputOption::VALUE_REQUIRED, "Number of items to display", 25)
48+
->addOption('all', 'a', InputOption::VALUE_NONE, "Display all items");
4949
}
5050

5151
public function execute(InputInterface $input, OutputInterface $output): int {
5252
$fileInput = $input->getArgument('file');
5353
$count = (int)$input->getOption('count');
54+
$all = $input->getOption('all');
5455
$node = $this->fileUtils->getNode($fileInput);
5556
if (!$node) {
5657
$output->writeln("<error>file $fileInput not found</error>");
5758
return 1;
5859
}
5960
$output->writeln($node->getName() . ": <info>" . Util::humanFileSize($node->getSize()) . "</info>");
6061
if ($node instanceof Folder) {
61-
$limits = array_fill(0, $count - 1, 0);
62-
$this->fileUtils->outputLargeFilesTree($output, $node, '', $limits);
62+
$limits = $all ? [] : array_fill(0, $count - 1, 0);
63+
$this->fileUtils->outputLargeFilesTree($output, $node, '', $limits, $all);
6364
}
6465
return 0;
6566
}
66-
6767
}

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,8 @@
960960
'OC\\Core\\Command\\Group\\ListCommand' => $baseDir . '/core/Command/Group/ListCommand.php',
961961
'OC\\Core\\Command\\Group\\RemoveUser' => $baseDir . '/core/Command/Group/RemoveUser.php',
962962
'OC\\Core\\Command\\Info\\File' => $baseDir . '/core/Command/Info/File.php',
963+
'OC\\Core\\Command\\Info\\FileUtils' => $baseDir . '/core/Command/Info/FileUtils.php',
964+
'OC\\Core\\Command\\Info\\Space' => $baseDir . '/core/Command/Info/Space.php',
963965
'OC\\Core\\Command\\Integrity\\CheckApp' => $baseDir . '/core/Command/Integrity/CheckApp.php',
964966
'OC\\Core\\Command\\Integrity\\CheckCore' => $baseDir . '/core/Command/Integrity/CheckCore.php',
965967
'OC\\Core\\Command\\Integrity\\SignApp' => $baseDir . '/core/Command/Integrity/SignApp.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
993993
'OC\\Core\\Command\\Group\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/Group/ListCommand.php',
994994
'OC\\Core\\Command\\Group\\RemoveUser' => __DIR__ . '/../../..' . '/core/Command/Group/RemoveUser.php',
995995
'OC\\Core\\Command\\Info\\File' => __DIR__ . '/../../..' . '/core/Command/Info/File.php',
996+
'OC\\Core\\Command\\Info\\FileUtils' => __DIR__ . '/../../..' . '/core/Command/Info/FileUtils.php',
997+
'OC\\Core\\Command\\Info\\Space' => __DIR__ . '/../../..' . '/core/Command/Info/Space.php',
996998
'OC\\Core\\Command\\Integrity\\CheckApp' => __DIR__ . '/../../..' . '/core/Command/Integrity/CheckApp.php',
997999
'OC\\Core\\Command\\Integrity\\CheckCore' => __DIR__ . '/../../..' . '/core/Command/Integrity/CheckCore.php',
9981000
'OC\\Core\\Command\\Integrity\\SignApp' => __DIR__ . '/../../..' . '/core/Command/Integrity/SignApp.php',

0 commit comments

Comments
 (0)