Log files:scan exception, add InterruptedException

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Vincent Petry 2017-02-10 15:24:25 +01:00 committed by Morris Jobke
parent 528a903a7b
commit b8a8f43fce
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
2 changed files with 36 additions and 8 deletions

View File

@ -30,6 +30,7 @@ namespace OCA\Files\Command;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use OC\Core\Command\Base; use OC\Core\Command\Base;
use OC\Core\Command\InterruptedException;
use OC\ForbiddenException; use OC\ForbiddenException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -117,14 +118,14 @@ class Scan extends Base {
$output->writeln("\tFile <info>$path</info>"); $output->writeln("\tFile <info>$path</info>");
$this->filesCounter += 1; $this->filesCounter += 1;
if ($this->hasBeenInterrupted()) { if ($this->hasBeenInterrupted()) {
throw new \Exception('ctrl-c'); throw new InterruptedException();
} }
}); });
$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>"); $output->writeln("\tFolder <info>$path</info>");
$this->foldersCounter += 1; $this->foldersCounter += 1;
if ($this->hasBeenInterrupted()) { if ($this->hasBeenInterrupted()) {
throw new \Exception('ctrl-c'); throw new InterruptedException();
} }
}); });
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { $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) { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) {
$this->filesCounter += 1; $this->filesCounter += 1;
if ($this->hasBeenInterrupted()) { if ($this->hasBeenInterrupted()) {
throw new \Exception('ctrl-c'); throw new InterruptedException();
} }
}); });
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) {
$this->foldersCounter += 1; $this->foldersCounter += 1;
if ($this->hasBeenInterrupted()) { if ($this->hasBeenInterrupted()) {
throw new \Exception('ctrl-c'); throw new InterruptedException();
} }
}); });
} }
@ -161,11 +162,12 @@ class Scan extends Base {
} catch (ForbiddenException $e) { } catch (ForbiddenException $e) {
$output->writeln("<error>Home storage for user $user not writable</error>"); $output->writeln("<error>Home storage for user $user 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) {
# exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user');
} catch (\Exception $e) { } catch (\Exception $e) {
if ($e->getMessage() !== 'ctrl-c') { $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>');
$output->writeln('<error>Exception while scanning: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . '</error>'); $output->writeln('<error>' . $e->getTraceAsString() . '</error>');
}
return;
} }
} }

View File

@ -0,0 +1,26 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/
namespace OC\Core\Command;
/**
* Exception for when the user hit ctrl-c
*/
class InterruptedException extends \Exception {}