Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #27136 from owncloud/stable9-logscanexception
[stable9] Log files:scan exception
  • Loading branch information
Vincent Petry committed Feb 21, 2017
2 parents 0cb919b + 1bb9ef3 commit a95aaf1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apps/files/command/scan.php
Expand Up @@ -28,6 +28,7 @@

use Doctrine\DBAL\Connection;
use OC\Core\Command\Base;
use OC\Core\Command\InterruptedException;
use OC\ForbiddenException;
use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection;
Expand Down Expand Up @@ -101,14 +102,14 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
$output->writeln("\tFile <info>$path</info>");
$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 <info>$path</info>");
$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) {
Expand All @@ -119,13 +120,13 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
$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();
}
});
}
Expand All @@ -135,9 +136,12 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
} catch (ForbiddenException $e) {
$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");
} catch (\Exception $e) {
} catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user');
return;
} catch (\Exception $e) {
$output->writeln('<error>Exception during scan: ' . $e->getMessage() . "\n" . $e->getTraceAsString() . '</error>');
}
}

Expand Down
26 changes: 26 additions & 0 deletions core/command/interruptedexception.php
@@ -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 {}

0 comments on commit a95aaf1

Please sign in to comment.