diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-01-08 12:22:19 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-01-08 12:22:19 +0100 |
commit | c9c6efd1572c620bdb00fb0ffedd003c6b48c193 (patch) | |
tree | ef4b25bc766ffd5b99c9c58231d193454a63067f | |
parent | f5952cbd7661611f4130236fb5ee65ee6c12a3f0 (diff) | |
parent | d523ed997a4d81467501f233e6690e0cb06fa90b (diff) | |
download | nextcloud-server-c9c6efd1572c620bdb00fb0ffedd003c6b48c193.tar.gz nextcloud-server-c9c6efd1572c620bdb00fb0ffedd003c6b48c193.zip |
Merge pull request #21314 from owncloud/scanner-skip-not-available-81
[8.1] Skip unavailable storages in scanner
-rw-r--r-- | apps/files/ajax/scan.php | 12 | ||||
-rw-r--r-- | apps/files/command/scan.php | 6 | ||||
-rw-r--r-- | lib/private/files/utils/scanner.php | 19 | ||||
-rw-r--r-- | tests/lib/files/etagtest.php | 2 | ||||
-rw-r--r-- | tests/lib/files/utils/scanner.php | 10 |
5 files changed, 36 insertions, 13 deletions
diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php index f7413094386..34b0e4c4cd3 100644 --- a/apps/files/ajax/scan.php +++ b/apps/files/ajax/scan.php @@ -50,10 +50,14 @@ foreach ($users as $user) { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($listener) { $listener->file(); }); - if ($force) { - $scanner->scan($dir); - } else { - $scanner->backgroundScan($dir); + try { + if ($force) { + $scanner->scan($dir); + } else { + $scanner->backgroundScan($dir); + } + } catch (\Exception $e) { + $eventSource->send('error', get_class($e) . ': ' . $e->getMessage()); } } diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php index 99ce64e09cc..31ae555e041 100644 --- a/apps/files/command/scan.php +++ b/apps/files/command/scan.php @@ -26,6 +26,7 @@ namespace OCA\Files\Command; use OC\ForbiddenException; +use OCP\Files\StorageNotAvailableException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -74,7 +75,7 @@ class Scan extends Command { } protected function scanFiles($user, $path, $quiet, OutputInterface $output) { - $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection()); + $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); if (!$quiet) { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { $output->writeln("Scanning file <info>$path</info>"); @@ -82,6 +83,9 @@ class Scan extends Command { $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { $output->writeln("Scanning folder <info>$path</info>"); }); + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { + $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")"); + }); } try { $scanner->scan($path); diff --git a/lib/private/files/utils/scanner.php b/lib/private/files/utils/scanner.php index 558a1fba028..d431df0cd12 100644 --- a/lib/private/files/utils/scanner.php +++ b/lib/private/files/utils/scanner.php @@ -30,6 +30,8 @@ use OC\Files\Cache\ChangePropagator; use OC\Files\Filesystem; use OC\ForbiddenException; use OC\Hooks\PublicEmitter; +use OCP\Files\StorageNotAvailableException; +use OCP\ILogger; /** * Class Scanner @@ -57,10 +59,17 @@ class Scanner extends PublicEmitter { protected $db; /** + * @var ILogger + */ + protected $logger; + + /** * @param string $user * @param \OCP\IDBConnection $db + * @param ILogger $logger */ - public function __construct($user, $db) { + public function __construct($user, $db, ILogger $logger) { + $this->logger = $logger; $this->user = $user; $this->propagator = new ChangePropagator(new View('')); $this->db = $db; @@ -156,7 +165,13 @@ class Scanner extends PublicEmitter { $scanner->setUseTransactions(false); $this->attachListener($mount); $this->db->beginTransaction(); - $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); + try { + $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); + } catch (StorageNotAvailableException $e) { + $this->logger->error('Storage ' . $storage->getId() . ' not available'); + $this->logger->error($e->getMessage()); + $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); + } $this->db->commit(); } $this->propagator->propagateChanges(time()); diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index c3d364d6800..503484353e4 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -60,7 +60,7 @@ class EtagTest extends \Test\TestCase { $files = array('/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'); $originalEtags = $this->getEtags($files); - $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection()); + $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index 75cd75ee3f5..cef7b6e89e1 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -70,7 +70,7 @@ class Scanner extends \Test\TestCase { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection()); + $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->addMount($mount); $scanner->scan(''); @@ -92,7 +92,7 @@ class Scanner extends \Test\TestCase { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection()); + $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->addMount($mount); $scanner->scan(''); @@ -130,7 +130,7 @@ class Scanner extends \Test\TestCase { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection()); + $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $this->assertFalse($cache->inCache('folder/bar.txt')); $scanner->scan('/' . $uid . '/files/foo'); @@ -152,7 +152,7 @@ class Scanner extends \Test\TestCase { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection()); + $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $originalPropagator = $scanner->getPropagator(); $scanner->setPropagator($propagator); $scanner->addMount($mount); @@ -214,7 +214,7 @@ class Scanner extends \Test\TestCase { * @param string $invalidPath */ public function testInvalidPathScanning($invalidPath) { - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection()); + $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->scan($invalidPath); } } |