add Scanner->backgroundScan

This commit is contained in:
Robin Appelman 2012-11-21 23:18:58 +01:00
parent 186c9e77e8
commit 8687e0d346
2 changed files with 32 additions and 0 deletions

View File

@ -121,4 +121,14 @@ class Scanner {
} }
return $size; return $size;
} }
/**
* walk over any folders that are not fully scanned yet and scan them
*/
public function backgroundScan() {
while ($path = $this->cache->getIncomplete()) {
$this->scan($path);
$this->cache->correctFolderSize($path);
}
}
} }

View File

@ -104,6 +104,28 @@ class Scanner extends \UnitTestCase {
$this->assertNotEqual($cachedDataFolder['size'], -1); $this->assertNotEqual($cachedDataFolder['size'], -1);
} }
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());
}
function setUp() { function setUp() {
$this->storage = new \OC\Files\Storage\Temporary(array()); $this->storage = new \OC\Files\Storage\Temporary(array());
$this->scanner = new \OC\Files\Cache\Scanner($this->storage); $this->scanner = new \OC\Files\Cache\Scanner($this->storage);