Skip to content

Commit

Permalink
Add an error counter
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed May 4, 2023
1 parent 2ffa9fc commit 88405d3
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions apps/files/lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Scan extends Base {
protected float $execTime = 0;
protected int $foldersCounter = 0;
protected int $filesCounter = 0;
protected int $errorsCounter = 0;
private IRootFolder $root;
private MetadataManager $metadataManager;

Expand Down Expand Up @@ -148,10 +149,12 @@ protected function scanFiles(string $user, string $path, bool $scanMetadata, Out

$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) {
$output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE);
++$this->errorsCounter;
});

$scanner->listen('\OC\Files\Utils\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output) {
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
++$this->errorsCounter;
});

try {
Expand All @@ -164,14 +167,17 @@ protected function scanFiles(string $user, string $path, bool $scanMetadata, Out
$output->writeln("<error>Home storage for user $user not writable or 'files' subdirectory missing</error>");
$output->writeln(' ' . $e->getMessage());
$output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
++$this->errorsCounter;
} catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user');
} catch (NotFoundException $e) {
$output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>');
++$this->errorsCounter;
} catch (\Exception $e) {
$output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>');
$output->writeln('<error>' . $e->getTraceAsString() . '</error>');
++$this->errorsCounter;
}
}

Expand Down Expand Up @@ -260,6 +266,7 @@ public function exceptionErrorHandler(OutputInterface $output, int $severity, st
$e = new \ErrorException($message, 0, $severity, $file, $line);
$output->writeln('<error>Error during scan: ' . $e->getMessage() . '</error>');
$output->writeln('<error>' . $e->getTraceAsString() . '</error>', OutputInterface::VERBOSITY_VERY_VERBOSE);
++$this->errorsCounter;
return true;
}

Expand All @@ -271,28 +278,18 @@ protected function presentStats(OutputInterface $output) {
$this->execTime += microtime(true);

$headers = [
'Folders', 'Files', 'Elapsed time'
'Folders',
'Files',
'Errors',
'Elapsed time',
];

$this->showSummary($headers, null, $output);
}

/**
* Shows a summary of operations
*
* @param string[] $headers
* @param string[] $rows
* @param OutputInterface $output
*/
protected function showSummary($headers, $rows, OutputInterface $output) {
$niceDate = $this->formatExecTime();
if (!$rows) {
$rows = [
$this->foldersCounter,
$this->filesCounter,
$niceDate,
];
}
$rows = [
$this->foldersCounter,
$this->filesCounter,
$this->errorsCounter,
$niceDate,
];
$table = new Table($output);
$table
->setHeaders($headers)
Expand Down

0 comments on commit 88405d3

Please sign in to comment.