From b8a8f43fce979d5ae23d8038daef1ba9b4b48d21 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 10 Feb 2017 15:24:25 +0100 Subject: [PATCH] Log files:scan exception, add InterruptedException Signed-off-by: Morris Jobke --- apps/files/lib/Command/Scan.php | 18 ++++++++++-------- core/Command/InterruptedException.php | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 core/Command/InterruptedException.php diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php index 0234fb435a..24b47aca9a 100644 --- a/apps/files/lib/Command/Scan.php +++ b/apps/files/lib/Command/Scan.php @@ -30,6 +30,7 @@ namespace OCA\Files\Command; use Doctrine\DBAL\Connection; use OC\Core\Command\Base; +use OC\Core\Command\InterruptedException; use OC\ForbiddenException; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; @@ -117,14 +118,14 @@ class Scan extends Base { $output->writeln("\tFile $path"); $this->filesCounter += 1; if ($this->hasBeenInterrupted()) { - throw new \Exception('ctrl-c'); + throw new InterruptedException(); } }); $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { $output->writeln("\tFolder $path"); $this->foldersCounter += 1; if ($this->hasBeenInterrupted()) { - throw new \Exception('ctrl-c'); + throw new InterruptedException(); } }); $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { @@ -135,13 +136,13 @@ class Scan extends Base { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { $this->filesCounter += 1; if ($this->hasBeenInterrupted()) { - throw new \Exception('ctrl-c'); + throw new InterruptedException(); } }); $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { $this->foldersCounter += 1; if ($this->hasBeenInterrupted()) { - throw new \Exception('ctrl-c'); + throw new InterruptedException(); } }); } @@ -161,11 +162,12 @@ class Scan extends Base { } catch (ForbiddenException $e) { $output->writeln("Home storage for user $user not writable"); $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); + } catch (InterruptedException $e) { + # exit the function if ctrl-c has been pressed + $output->writeln('Interrupted by user'); } catch (\Exception $e) { - if ($e->getMessage() !== 'ctrl-c') { - $output->writeln('Exception while scanning: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . ''); - } - return; + $output->writeln('Exception during scan: ' . $e->getMessage() . ''); + $output->writeln('' . $e->getTraceAsString() . ''); } } diff --git a/core/Command/InterruptedException.php b/core/Command/InterruptedException.php new file mode 100644 index 0000000000..ef81b5d939 --- /dev/null +++ b/core/Command/InterruptedException.php @@ -0,0 +1,26 @@ + + * + * @copyright Copyright (c) 2017, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OC\Core\Command; + +/** + * Exception for when the user hit ctrl-c + */ +class InterruptedException extends \Exception {}