From 264b4ad3a911ba629e2a7551d64482aaaf707b99 Mon Sep 17 00:00:00 2001 From: Ari Selseng Date: Fri, 1 Mar 2019 23:52:58 +0100 Subject: Avoid calculating folder size for parent that needs scan. Signed-off-by: Ari Selseng --- tests/lib/Files/Cache/ScannerTest.php | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/lib') diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index 736df2174d1..0f5335f4416 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -203,6 +203,44 @@ class ScannerTest extends \Test\TestCase { $this->assertFalse($this->cache->getIncomplete()); } + public function testBackgroundScanNestedIncompleteFolders() { + $this->storage->mkdir('folder'); + $this->scanner->backgroundScan(); + + $this->storage->mkdir('folder/subfolder1'); + $this->storage->mkdir('folder/subfolder2'); + + $this->storage->mkdir('folder/subfolder1/subfolder3'); + $this->cache->put('folder', ['size' => -1]); + $this->cache->put('folder/subfolder1', ['size' => -1]); + + // do a scan to get the folders into the cache. + $this->scanner->backgroundScan(); + + $this->assertTrue($this->cache->inCache('folder/subfolder1/subfolder3')); + + $this->storage->file_put_contents('folder/subfolder1/bar1.txt', 'foobar'); + $this->storage->file_put_contents('folder/subfolder1/subfolder3/bar3.txt', 'foobar'); + $this->storage->file_put_contents('folder/subfolder2/bar2.txt', 'foobar'); + + //mark folders as incomplete. + $this->cache->put('folder/subfolder1', ['size' => -1]); + $this->cache->put('folder/subfolder2', ['size' => -1]); + $this->cache->put('folder/subfolder1/subfolder3', ['size' => -1]); + + $this->scanner->backgroundScan(); + + $this->assertTrue($this->cache->inCache('folder/subfolder1/bar1.txt')); + $this->assertTrue($this->cache->inCache('folder/subfolder2/bar2.txt')); + $this->assertTrue($this->cache->inCache('folder/subfolder1/subfolder3/bar3.txt')); + + //check if folder sizes are correct. + $this->assertEquals(18, $this->cache->get('folder')['size']); + $this->assertEquals(12, $this->cache->get('folder/subfolder1')['size']); + $this->assertEquals(6, $this->cache->get('folder/subfolder1/subfolder3')['size']); + $this->assertEquals(6, $this->cache->get('folder/subfolder2')['size']); + } + public function testReuseExisting() { $this->fillTestFolders(); -- cgit v1.2.3