|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/** |
|
5
|
|
|
* @copyright Copyright (c) 2023 Robin Appelman <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OC\Core\Command\Info; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\Files\Folder; |
|
27
|
|
|
use OCP\Util; |
|
28
|
|
|
use Symfony\Component\Console\Command\Command; |
|
29
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
31
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
32
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
33
|
|
|
|
|
34
|
|
|
class Space extends Command { |
|
35
|
|
|
private FileUtils $fileUtils; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct(FileUtils $fileUtils) { |
|
38
|
|
|
$this->fileUtils = $fileUtils; |
|
39
|
|
|
parent::__construct(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function configure(): void { |
|
43
|
|
|
$this |
|
44
|
|
|
->setName('info:file:space') |
|
45
|
|
|
->setDescription('Summarize space usage of specified folder') |
|
46
|
|
|
->addArgument('file', InputArgument::REQUIRED, "File id or path") |
|
47
|
|
|
->addOption('count', 'c', InputOption::VALUE_REQUIRED, "Number of items to display", 25) |
|
48
|
|
|
->addOption('all', 'a', InputOption::VALUE_NONE, "Display all items"); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int { |
|
52
|
|
|
$fileInput = $input->getArgument('file'); |
|
53
|
|
|
$count = (int)$input->getOption('count'); |
|
54
|
|
|
$all = $input->getOption('all'); |
|
55
|
|
|
$node = $this->fileUtils->getNode($fileInput); |
|
56
|
|
|
if (!$node) { |
|
57
|
|
|
$output->writeln("<error>file $fileInput not found</error>"); |
|
58
|
|
|
return 1; |
|
59
|
|
|
} |
|
60
|
|
|
$output->writeln($node->getName() . ": <info>" . Util::humanFileSize($node->getSize()) . "</info>"); |
|
61
|
|
|
if ($node instanceof Folder) { |
|
62
|
|
|
$limits = $all ? [] : array_fill(0, $count - 1, 0); |
|
63
|
|
|
$this->fileUtils->outputLargeFilesTree($output, $node, '', $limits, $all); |
|
64
|
|
|
} |
|
65
|
|
|
return 0; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|