]> source.dussan.org Git - nextcloud-server.git/commitdiff
Skip unavailable storages in scanner
authorRobin Appelman <icewind@owncloud.com>
Fri, 27 Nov 2015 13:02:50 +0000 (14:02 +0100)
committerRobin Appelman <icewind@owncloud.com>
Fri, 27 Nov 2015 13:02:50 +0000 (14:02 +0100)
apps/files/ajax/scan.php
apps/files/command/scan.php
lib/private/files/utils/scanner.php
tests/lib/files/etagtest.php
tests/lib/files/utils/scanner.php

index 759f2d15f84fed9dcba81b9e172bf8cf4f781e3a..7710a28a8ca7a83ddf11ae338d1d223d5f6217f6 100644 (file)
@@ -47,7 +47,7 @@ $listener = new ScanListener($eventSource);
 
 foreach ($users as $user) {
        $eventSource->send('user', $user);
-       $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection());
+       $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger());
        $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', array($listener, 'file'));
        try {
                if ($force) {
index 99ce64e09cc96d73430725374c302e022a6c0245..31ae555e0419e61ce88d78c5a789017781e31fba 100644 (file)
@@ -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);
index 460c8007bf4cacf445625a122ad9aed6c06ad7d4..9b3bae0b9aab307c11a62f802917935379e2a992 100644 (file)
@@ -32,6 +32,8 @@ use OC\Files\Filesystem;
 use OC\ForbiddenException;
 use OC\Hooks\PublicEmitter;
 use OC\Lock\DBLockingProvider;
+use OCP\Files\StorageNotAvailableException;
+use OCP\ILogger;
 
 /**
  * Class Scanner
@@ -58,11 +60,18 @@ 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;
@@ -161,7 +170,12 @@ class Scanner extends PublicEmitter {
                        if (!$isDbLocking) {
                                $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->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]);
+                       }
                        if (!$isDbLocking) {
                                $this->db->commit();
                        }
index 192768d04afdf9946951fdf12602f0ac613f255a..1b51030d4a31110591dc82ebed80220e90451574 100644 (file)
@@ -59,7 +59,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);
index 5492774f42e31db022ea9093de0451bf865365e7..b731c6992e80bbc0be429c112bed078905459f2f 100644 (file)
@@ -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);
        }
 }