summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2023-05-11 15:13:05 +0200
committerGitHub <noreply@github.com>2023-05-11 15:13:05 +0200
commitf1bfd7fd484c28729f6c2a5e8f80bec5f6565f47 (patch)
treebd37fcd6663616162dd2e49aed2d86187e36962f
parentb7602cad74a8f34493b5dce13f4256bf4d14db9d (diff)
parentf664d42bb0a2ce29dbaee7c5e174878cd0176f08 (diff)
downloadnextcloud-server-f1bfd7fd484c28729f6c2a5e8f80bec5f6565f47.tar.gz
nextcloud-server-f1bfd7fd484c28729f6c2a5e8f80bec5f6565f47.zip
Merge pull request #38154 from nextcloud/backport/37944/stable26
[stable26] Do not stop at the first PHP error/warning in files:scan
-rw-r--r--apps/files/lib/Command/Scan.php69
1 files changed, 33 insertions, 36 deletions
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php
index 710c76de493..2cf230f3f57 100644
--- a/apps/files/lib/Command/Scan.php
+++ b/apps/files/lib/Command/Scan.php
@@ -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;
@@ -148,10 +149,12 @@ class Scan extends Base {
$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 {
@@ -163,14 +166,17 @@ class Scan extends Base {
} catch (ForbiddenException $e) {
$output->writeln("<error>Home storage for user $user not writable or 'files' subdirectory missing</error>");
$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;
}
}
@@ -191,11 +197,6 @@ class Scan extends Base {
$users = $input->getArgument('user_id');
}
- # restrict the verbosity level to VERBOSITY_VERBOSE
- if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
- $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
- }
-
# check quantity of users to be process and show it on the command line
$users_total = count($users);
if ($users_total === 0) {
@@ -203,7 +204,7 @@ class Scan extends Base {
return 1;
}
- $this->initTools();
+ $this->initTools($output);
$user_count = 0;
foreach ($users as $user) {
@@ -235,15 +236,19 @@ class Scan extends Base {
/**
* Initialises some useful tools for the Command
*/
- protected function initTools() {
+ protected function initTools(OutputInterface $output) {
// Start the timer
$this->execTime = -microtime(true);
// Convert PHP errors to exceptions
- set_error_handler([$this, 'exceptionErrorHandler'], E_ALL);
+ set_error_handler(
+ fn (int $severity, string $message, string $file, int $line): bool =>
+ $this->exceptionErrorHandler($output, $severity, $message, $file, $line),
+ E_ALL
+ );
}
/**
- * Processes PHP errors as exceptions in order to be able to keep track of problems
+ * Processes PHP errors in order to be able to show them in the output
*
* @see https://www.php.net/manual/en/function.set-error-handler.php
*
@@ -251,15 +256,17 @@ class Scan extends Base {
* @param string $message
* @param string $file the filename that the error was raised in
* @param int $line the line number the error was raised
- *
- * @throws \ErrorException
*/
- public function exceptionErrorHandler($severity, $message, $file, $line) {
- if (!(error_reporting() & $severity)) {
- // This error code is not included in error_reporting
- return;
+ public function exceptionErrorHandler(OutputInterface $output, int $severity, string $message, string $file, int $line): bool {
+ if (($severity === E_DEPRECATED) || ($severity === E_USER_DEPRECATED)) {
+ // Do not show deprecation warnings
+ return false;
}
- throw new \ErrorException($message, 0, $severity, $file, $line);
+ $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;
}
/**
@@ -270,28 +277,18 @@ class Scan extends Base {
$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)