Merge pull request #23576 from owncloud/background-scan-unscanned-9

[9.0] handle completely unscanned storages in the background scanner
This commit is contained in:
Thomas Müller 2016-04-20 20:22:07 +02:00
commit fdab395925
1 changed files with 31 additions and 19 deletions

View File

@ -448,26 +448,38 @@ class Scanner extends BasicEmitter implements IScanner {
* walk over any folders that are not fully scanned yet and scan them * walk over any folders that are not fully scanned yet and scan them
*/ */
public function backgroundScan() { public function backgroundScan() {
$lastPath = null; if (!$this->cache->inCache('')) {
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { $this->runBackgroundScanJob(function () {
try { $this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG);
$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); }, '');
\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path)); } else {
if ($this->cacheActive) { $lastPath = null;
$this->cache->correctFolderSize($path); while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
} $this->runBackgroundScanJob(function() use ($path) {
} catch (\OCP\Files\StorageInvalidException $e) { $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
// skip unavailable storages }, $path);
} catch (\OCP\Files\StorageNotAvailableException $e) { // FIXME: this won't proceed with the next item, needs revamping of getIncomplete()
// skip unavailable storages // to make this possible
} catch (\OCP\Files\ForbiddenException $e) { $lastPath = $path;
// skip forbidden 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;
private function runBackgroundScanJob(callable $callback, $path) {
try {
$callback();
\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\Files\ForbiddenException $e) {
// skip forbidden storages
} catch (\OCP\Lock\LockedException $e) {
// skip unavailable storages
} }
} }