Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions tests/lib/Files/Cache/ScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public function testBackgroundScan(): void {

$this->scanner->scan('', IScanner::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'));
$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'));
$this->assertTrue($this->cache->inCache('folder2/bar.txt'));

$cachedData = $this->cache->get('');
$this->assertnotEquals(-1, $cachedData['size']);
Expand All @@ -182,16 +182,15 @@ public function testBackgroundScanOnlyRecurseIncomplete(): void {

$this->scanner->scan('', IScanner::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
// Mark folder2 complete so the incomplete-only scan skips its contents.
$this->cache->put('folder2', ['size' => 1]);

$cachedData = $this->cache->get('');
$this->assertEquals(-1, $cachedData['size']);

$this->scanner->scan('', IScanner::SCAN_RECURSIVE_INCOMPLETE, IScanner::REUSE_ETAG | IScanner::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'));

Expand All @@ -212,7 +211,7 @@ public function testBackgroundScanNestedIncompleteFolders(): void {
$this->cache->put('folder', ['size' => -1]);
$this->cache->put('folder/subfolder1', ['size' => -1]);

// do a scan to get the folders into the cache.
// Cache the newly created directory tree before adding files to it.
$this->scanner->backgroundScan();

$this->assertTrue($this->cache->inCache('folder/subfolder1/subfolder3'));
Expand All @@ -221,7 +220,7 @@ public function testBackgroundScanNestedIncompleteFolders(): void {
$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.
// Mark the new files' parent folders incomplete to simulate notifications.
$this->cache->put('folder/subfolder1', ['size' => -1]);
$this->cache->put('folder/subfolder2', ['size' => -1]);
$this->cache->put('folder/subfolder1/subfolder3', ['size' => -1]);
Expand All @@ -232,7 +231,6 @@ public function testBackgroundScanNestedIncompleteFolders(): void {
$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']);
Expand Down Expand Up @@ -314,7 +312,7 @@ public function testETagRecreation(): void {

$this->scanner->scan('folder/bar.txt');

// manipulate etag to simulate an empty etag
// Simulate a cached file with an empty ETag.
$this->scanner->scan('', IScanner::SCAN_SHALLOW, IScanner::REUSE_ETAG);
/** @var CacheEntry $data0 */
$data0 = $this->cache->get('folder/bar.txt');
Expand All @@ -326,10 +324,10 @@ public function testETagRecreation(): void {
$data0['etag'] = '';
$this->cache->put('folder/bar.txt', $data0->getData());

// rescan
// Rescanning must replace the empty cached ETag.
$this->scanner->scan('folder/bar.txt', IScanner::SCAN_SHALLOW, IScanner::REUSE_ETAG);

// verify cache content
// The recreated ETag must be non-empty.
$newData0 = $this->cache->get('folder/bar.txt');
$this->assertIsString($newData0['etag']);
$this->assertNotEmpty($newData0['etag']);
Expand Down Expand Up @@ -415,14 +413,14 @@ public function testNoETagUnscannedFolder(): void {
$this->scanner->scan('');

$oldFolderEntry = $this->cache->get('folder');
// create a new file in a folder by keeping the mtime unchanged, but mark the folder as unscanned
// Add a file without changing the folder mtime, then mark the folder unscanned.
$this->storage->file_put_contents('folder/new.txt', 'foo');
$this->storage->touch('folder', $oldFolderEntry->getMTime());
$this->cache->update($oldFolderEntry->getId(), ['size' => -1]);

$this->scanner->scan('');

$this->cache->inCache('folder/new.txt');
$this->assertTrue($this->cache->inCache('folder/new.txt'));

$newFolderEntry = $this->cache->get('folder');
$this->assertNotEquals($newFolderEntry->getEtag(), $oldFolderEntry->getEtag());
Expand All @@ -436,17 +434,18 @@ public function testNoETagUnscannedSubFolder(): void {

$oldFolderEntry1 = $this->cache->get('folder');
$oldFolderEntry2 = $this->cache->get('folder/sub');
// create a new file in a folder by keeping the mtime unchanged, but mark the folder as unscanned
// Add a file without changing its parent folder's mtime, then mark that folder unscanned.
$this->storage->file_put_contents('folder/sub/new.txt', 'foo');
$this->storage->touch('folder/sub', $oldFolderEntry1->getMTime());
$this->storage->touch('folder/sub', $oldFolderEntry2->getMTime());

// we only mark the direct parent as unscanned, which is the current "notify" behavior
// Notifications mark the new file's direct parent as unscanned, not its ancestors.
$this->cache->update($oldFolderEntry2->getId(), ['size' => -1]);

$this->scanner->scan('');

$this->cache->inCache('folder/new.txt');
$this->assertTrue($this->cache->inCache('folder/sub/new.txt'));

// The changed subfolder ETag must also be reflected in its ancestor.
$newFolderEntry1 = $this->cache->get('folder');
$this->assertNotEquals($newFolderEntry1->getEtag(), $oldFolderEntry1->getEtag());
$newFolderEntry2 = $this->cache->get('folder/sub');
Expand Down
Loading