1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Robin Appelman <robin@icewind.nl>
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
*/
namespace OCA\GroupFolders\Command;
use OC\Files\ObjectStore\NoopScanner;
use OCP\Constants;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use OCP\Files\Cache\IScanner;
class Scan extends FolderCommand {
private int $foldersCounter = 0;
private int $filesCounter = 0;
protected function configure() {
$this
->setName('groupfolders:scan')
->setDescription('Scan a group folder for outside changes')
->addArgument('folder_id', InputArgument::REQUIRED, 'Id of the folder to configure');
parent::configure();
}
/** @psalm-suppress UndefinedInterfaceMethod setUseTransactions is defined in private class */
protected function execute(InputInterface $input, OutputInterface $output) {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
return -1;
}
$mount = $this->mountProvider->getMount($folder['id'], '/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota']);
/** @var IScanner&\OC\Hooks\BasicEmitter $scanner */
$scanner = $mount->getStorage()->getScanner();
if ($scanner instanceof NoopScanner) {
$output->writeln("Scanning group folders using an object store as primary storage is not supported.");
return -1;
}
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("\tFile\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
++$this->filesCounter;
// abortIfInterrupted doesn't exist in nc14
if (method_exists($this, 'abortIfInterrupted')) {
$this->abortIfInterrupted();
}
});
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($output) {
$output->writeln("\tFolder\t<info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
++$this->foldersCounter;
// abortIfInterrupted doesn't exist in nc14
if (method_exists($this, 'abortIfInterrupted')) {
$this->abortIfInterrupted();
}
});
$start = microtime(true);
$scanner->setUseTransactions(false);
$scanner->scan('');
$end = microtime(true);
$headers = [
'Folders', 'Files', 'Elapsed time'
];
$this->showSummary($headers, null, $output, $end - $start);
return 0;
}
protected function showSummary($headers, $rows, OutputInterface $output, float $duration): void {
$niceDate = date('H:i:s', (int)$duration);
if (!$rows) {
$rows = [
$this->foldersCounter,
$this->filesCounter,
$niceDate,
];
}
$table = new Table($output);
$table
->setHeaders($headers)
->setRows([$rows]);
$table->render();
}
}
|