Merge pull request #11968 from nextcloud/feature/noid/drop-verbose-appscan

Replace $verbose with VERBOSITY_VERBOSE for scanFiles method
This commit is contained in:
Daniel Kesselberg 2018-11-06 14:41:39 +01:00 committed by GitHub
commit ccd89f366d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 61 deletions

View File

@ -33,7 +33,6 @@ use OCP\Files\StorageNotAvailableException;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\Table;
@ -62,19 +61,7 @@ class ScanAppData extends Base {
$this $this
->setName('files:scan-app-data') ->setName('files:scan-app-data')
->setDescription('rescan the AppData folder') ->setDescription('rescan the AppData folder');
->addOption(
'quiet',
'q',
InputOption::VALUE_NONE,
'suppress any output'
)
->addOption(
'verbose',
'-v|vv|vvv',
InputOption::VALUE_NONE,
'verbose the output'
);
} }
public function checkScanWarning($fullPath, OutputInterface $output) { public function checkScanWarning($fullPath, OutputInterface $output) {
@ -86,7 +73,7 @@ class ScanAppData extends Base {
} }
} }
protected function scanFiles($verbose, OutputInterface $output) { protected function scanFiles(OutputInterface $output) {
try { try {
$appData = $this->getAppDataFolder(); $appData = $this->getAppDataFolder();
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
@ -96,44 +83,36 @@ class ScanAppData extends Base {
$connection = $this->reconnectToDatabase($output); $connection = $this->reconnectToDatabase($output);
$scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->getLogger()); $scanner = new \OC\Files\Utils\Scanner(null, $connection, \OC::$server->getLogger());
# check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception
# printout and count $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
if ($verbose) { $output->writeln("\tFile <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { ++$this->filesCounter;
$output->writeln("\tFile <info>$path</info>"); $this->abortIfInterrupted();
$this->filesCounter += 1; });
$this->abortIfInterrupted();
}); $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { $output->writeln("\tFolder <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE);
$output->writeln("\tFolder <info>$path</info>"); ++$this->foldersCounter;
$this->foldersCounter += 1; $this->abortIfInterrupted();
$this->abortIfInterrupted(); });
});
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) {
$output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')'); $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE);
}); });
# count only
} else { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) {
$this->filesCounter += 1;
$this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) {
$this->foldersCounter += 1;
$this->abortIfInterrupted();
});
}
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) {
$this->checkScanWarning($path, $output); $this->checkScanWarning($path, $output);
}); });
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$this->checkScanWarning($path, $output); $this->checkScanWarning($path, $output);
}); });
try { try {
$scanner->scan($appData->getPath()); $scanner->scan($appData->getPath());
} catch (ForbiddenException $e) { } catch (ForbiddenException $e) {
$output->writeln("<error>Storage not writable</error>"); $output->writeln('<error>Storage not writable</error>');
$output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
} catch (InterruptedException $e) { } catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed # exit the function if ctrl-c has been pressed
@ -148,33 +127,18 @@ class ScanAppData extends Base {
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output) {
# no messaging level option means: no full printout but statistics
# $quiet means no print at all
# $verbose means full printout including statistics
# -q -v full stat
# 0 0 no yes
# 0 1 yes yes
# 1 -- no no (quiet overrules verbose)
$verbose = $input->getOption('verbose');
$quiet = $input->getOption('quiet');
# restrict the verbosity level to VERBOSITY_VERBOSE # restrict the verbosity level to VERBOSITY_VERBOSE
if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
} }
if ($quiet) {
$verbose = false;
}
$output->writeln("\nScanning AppData for files"); $output->writeln("\nScanning AppData for files");
$this->initTools(); $this->initTools();
$this->scanFiles($verbose, $output); $this->scanFiles($output);
# stat: printout statistics if $quiet was not set $this->presentStats($output);
if (!$quiet) {
$this->presentStats($output);
}
} }
/** /**