]> source.dussan.org Git - nextcloud-server.git/commitdiff
add tests for reusing existing data in scanner
authorRobin Appelman <icewind@owncloud.com>
Mon, 17 Jun 2013 16:03:57 +0000 (18:03 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 19 Jun 2013 11:33:25 +0000 (13:33 +0200)
lib/files/cache/scanner.php
tests/lib/files/cache/scanner.php

index 4cb856bfaec8719e2fb05839cce48525d2189a33..fe237c26cfadf249203fa517af0be71e59e06399 100644 (file)
@@ -118,7 +118,7 @@ class Scanner {
                        $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
                }
                $this->scanFile($path, $reuse);
-               return $this->scanChildren($path, $recursive);
+               return $this->scanChildren($path, $recursive, $reuse);
        }
 
        /**
@@ -164,9 +164,7 @@ class Scanner {
                                        $size += $childSize;
                                }
                        }
-                       if ($size !== -1) {
-                               $this->cache->put($path, array('size' => $size));
-                       }
+                       $this->cache->put($path, array('size' => $size));
                }
                return $size;
        }
index 3885c99e6d325121c260547c39ea1cfa02995531..3dacefa2b801dab56f6a34b8d26ddfb4f5312218 100644 (file)
@@ -104,7 +104,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
                $this->assertNotEquals($cachedDataFolder['size'], -1);
        }
 
-       function testBackgroundScan(){
+       function testBackgroundScan() {
                $this->fillTestFolders();
                $this->storage->mkdir('folder2');
                $this->storage->file_put_contents('folder2/bar.txt', 'foobar');
@@ -126,6 +126,24 @@ class Scanner extends \PHPUnit_Framework_TestCase {
                $this->assertFalse($this->cache->getIncomplete());
        }
 
+       public function testReuseExisting() {
+               $this->fillTestFolders();
+
+               $this->scanner->scan('');
+               $oldData = $this->cache->get('');
+               $this->storage->unlink('folder/bar.txt');
+               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE);
+               $newData = $this->cache->get('');
+               $this->assertNotEquals($oldData['etag'], $newData['etag']);
+               $this->assertEquals($oldData['size'], $newData['size']);
+
+               $oldData = $newData;
+               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
+               $newData = $this->cache->get('');
+               $this->assertEquals($oldData['etag'], $newData['etag']);
+               $this->assertEquals(-1, $newData['size']);
+       }
+
        function setUp() {
                $this->storage = new \OC\Files\Storage\Temporary(array());
                $this->scanner = new \OC\Files\Cache\Scanner($this->storage);