Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set exit code if something went wrong. #20673

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions apps/files/lib/Command/ScanAppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ public function checkScanWarning($fullPath, OutputInterface $output) {
}
}

protected function scanFiles(OutputInterface $output, string $folder) {
protected function scanFiles(OutputInterface $output, string $folder): int {
try {
$appData = $this->getAppDataFolder();
} catch (NotFoundException $e) {
$output->writeln('NoAppData folder found');
return;
$output->writeln('<error>NoAppData folder found</error>');
return 1;
}

if ($folder !== '') {
try {
$appData = $appData->get($folder);
} catch (NotFoundException $e) {
$output->writeln('Could not find folder: ' . $folder);
return;
$output->writeln('<error>Could not find folder: ' . $folder . '</error>');
return 1;
}
}

Expand Down Expand Up @@ -130,16 +130,22 @@ protected function scanFiles(OutputInterface $output, string $folder) {
$scanner->scan($appData->getPath());
} catch (ForbiddenException $e) {
$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('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>');
return 1;
} catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user');
$output->writeln('<info>Interrupted by user</info>');
return 1;
} catch (NotFoundException $e) {
$output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>');
return 1;
} catch (\Exception $e) {
$output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>');
$output->writeln('<error>' . $e->getTraceAsString() . '</error>');
return 1;
}

return 0;
}


Expand All @@ -149,15 +155,18 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
}

$output->writeln("\nScanning AppData for files");
$output->writeln('Scanning AppData for files');
$output->writeln('');

$folder = $input->getArgument('folder');

$this->initTools();

$this->scanFiles($output, $folder);

$this->presentStats($output);
$exitCode = $this->scanFiles($output, $folder);
if ($exitCode === 0) {
$this->presentStats($output);
}
return $exitCode;
}

/**
Expand Down Expand Up @@ -196,7 +205,6 @@ public function exceptionErrorHandler($severity, $message, $file, $line) {
protected function presentStats(OutputInterface $output) {
// Stop the timer
$this->execTime += microtime(true);
$output->writeln("");

$headers = [
'Folders', 'Files', 'Elapsed time'
Expand Down