/** * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); $this->cache->correctFolderSize($path); $lastPath = $path; } }
/** * walk over any folders that are not fully scanned yet and scan them */ 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); } $lastPath = $path; } }
function testGetIncomplete() { $file1 = 'folder1'; $file2 = 'folder2'; $file3 = 'folder3'; $file4 = 'folder4'; $data = array('size' => 10, 'mtime' => 50, 'mimetype' => 'foo/bar'); $this->cache->put($file1, $data); $data['size'] = -1; $this->cache->put($file2, $data); $this->cache->put($file3, $data); $data['size'] = 12; $this->cache->put($file4, $data); $this->assertEquals($file3, $this->cache->getIncomplete()); }
function testBackgroundScan() { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW); $this->assertFalse($this->cache->inCache('folder/bar.txt')); $this->assertFalse($this->cache->inCache('folder/2bar.txt')); $cachedData = $this->cache->get(''); $this->assertEquals(-1, $cachedData['size']); $this->scanner->backgroundScan(); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $cachedData = $this->cache->get(''); $this->assertnotEquals(-1, $cachedData['size']); $this->assertFalse($this->cache->getIncomplete()); }
/** * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { if (!$this->cache->inCache('')) { $this->runBackgroundScanJob(function () { $this->scan('', self::SCAN_RECURSIVE, self::REUSE_ETAG); }, ''); } else { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { $this->runBackgroundScanJob(function () use($path) { $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG); }, $path); // FIXME: this won't proceed with the next item, needs revamping of getIncomplete() // to make this possible $lastPath = $path; } } }
function testBackgroundScanOnlyRecurseIncomplete() { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW); $this->assertFalse($this->cache->inCache('folder/bar.txt')); $this->assertFalse($this->cache->inCache('folder/2bar.txt')); $this->assertFalse($this->cache->inCache('folder2/bar.txt')); $this->cache->put('folder2', ['size' => 1]); // mark as complete $cachedData = $this->cache->get(''); $this->assertEquals(-1, $cachedData['size']); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE_INCOMPLETE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $this->assertFalse($this->cache->inCache('folder2/bar.txt')); $cachedData = $this->cache->get(''); $this->assertNotEquals(-1, $cachedData['size']); $this->assertFalse($this->cache->getIncomplete()); }
/** * walk over any folders that are not fully scanned yet and scan them */ public function backgroundScan() { $lastPath = null; while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) { 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; } }
/** * find a folder in the cache which has not been fully scanned * * If multiple incomplete folders are in the cache, the one with the highest id will be returned, * use the one with the highest id gives the best result with the background scanner, since that is most * likely the folder where we stopped scanning previously * * @return string|bool the path of the folder or false when no folder matched */ public function getIncomplete() { return $this->cache->getIncomplete(); }