From fe575feca85ee6e6bb7b8b423a60d377bd364193 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 24 Aug 2015 16:42:53 +0200 Subject: [PATCH] Prevent scanner going crazy with unavailable storages --- apps/files/ajax/scan.php | 12 ++++++++---- apps/files/js/files.js | 3 +++ lib/private/files/cache/scanner.php | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php index 3f430cd27e..7d47a538fa 100644 --- a/apps/files/ajax/scan.php +++ b/apps/files/ajax/scan.php @@ -49,10 +49,14 @@ foreach ($users as $user) { $scanner = new \OC\Files\Utils\Scanner($user, \OC::$server->getDatabaseConnection()); $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', array($listener, 'file')); $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', array($listener, 'folder')); - 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/js/files.js b/apps/files/js/files.js index 245648a79e..4fdc9eb211 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -333,6 +333,9 @@ function scanFiles(force, dir, users) { scannerEventSource.listen('folder',function(path) { console.log('now scanning ' + path); }); + scannerEventSource.listen('error',function(message) { + console.error('Scanner error: ', message); + }); scannerEventSource.listen('done',function(count) { scanFiles.scanning=false; console.log('done after ' + count + ' files'); diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 7c65c72135..f76ef5ba0d 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -416,11 +416,21 @@ class Scanner extends BasicEmitter { public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { - $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); - \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path)); - if ($this->cacheActive) { - $this->cache->correctFolderSize($path); + try { + $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); + \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path)); + if ($this->cacheActive) { + $this->cache->correctFolderSize($path); + } + } catch (\OCP\Files\StorageInvalidException $e) { + // skip unavailable storages + } catch (\OCP\Files\StorageNotAvailableException $e) { + // skip unavailable storages + } catch (\OCP\Lock\LockedException $e) { + // skip unavailable storages } + // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() + // to make this possible $lastPath = $path; } }