]> source.dussan.org Git - nextcloud-server.git/commitdiff
etag changes are now propagated up the file tree
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 16 Sep 2013 21:32:17 +0000 (23:32 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 16 Sep 2013 21:32:17 +0000 (23:32 +0200)
lib/files/cache/scanner.php
tests/lib/files/cache/scanner.php

index 78cab6ed2da8a46865b36a3adc080d91440574ca..fdbce0d51fee454d2d7d841ac71a133c97c1bacb 100644 (file)
@@ -99,8 +99,10 @@ class Scanner extends BasicEmitter {
                                if ($reuseExisting and $cacheData = $this->cache->get($file)) {
                                        // prevent empty etag
                                        $etag = $cacheData['etag'];
+                                       $propagateETagChange = false;
                                        if (empty($etag)) {
                                                $etag = $data['etag'];
+                                               $propagateETagChange = true;
                                        }
 
                                        // only reuse data if the file hasn't explicitly changed
@@ -110,6 +112,18 @@ class Scanner extends BasicEmitter {
                                                }
                                                if ($reuseExisting & self::REUSE_ETAG) {
                                                        $data['etag'] = $etag;
+                                                       if ($propagateETagChange) {
+                                                               $parent = $file;
+                                                               while ($parent !== '') {
+                                                                       $parent = dirname($parent);
+                                                                       if ($parent === '.') {
+                                                                               $parent = '';
+                                                                       }
+                                                                       $parentCacheData = $this->cache->get($parent);
+                                                                       $parentCacheData['etag'] = $this->storage->getETag($parent);
+                                                                       $this->cache->put($parent, $parentCacheData);
+                                                               }
+                                                       }
                                                }
                                        }
                                        // Only update metadata that has changed
index fa1b3406040a107a469c27f91f42e4f37377d36a..b137799bbcfc078f447962356cb49da95170d439 100644 (file)
@@ -187,17 +187,26 @@ class Scanner extends \PHPUnit_Framework_TestCase {
        public function testETagRecreation() {
                $this->fillTestFolders();
 
-               $this->scanner->scan('');
+               $this->scanner->scan('folder/bar.txt');
 
                // manipulate etag to simulate an empty etag
                $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
-               $data['etag'] = '';
-               $this->cache->put('', $data);
+               $data0 = $this->cache->get('folder/bar.txt');
+               $data1 = $this->cache->get('folder');
+               $data2 = $this->cache->get('');
+               $data0['etag'] = '';
+               $this->cache->put('folder/bar.txt', $data0);
 
                // rescan
-               $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
-               $newData = $this->cache->get('');
-               $this->assertNotEmpty($newData['etag']);
+               $this->scanner->scan('folder/bar.txt', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
+
+               // verify cache content
+               $newData0 = $this->cache->get('folder/bar.txt');
+               $newData1 = $this->cache->get('folder');
+               $newData2 = $this->cache->get('');
+               $this->assertNotEmpty($newData0['etag']);
+               $this->assertNotEquals($data1['etag'], $newData1['etag']);
+               $this->assertNotEquals($data2['etag'], $newData2['etag']);
 
        }