]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cherry-pick of 5d671a8 onto stable5.
authorAndreas Fischer <bantu@owncloud.com>
Mon, 23 Sep 2013 14:13:12 +0000 (07:13 -0700)
committerAndreas Fischer <bantu@owncloud.com>
Sun, 29 Sep 2013 21:24:33 +0000 (23:24 +0200)
recreate an etag within the scanner if the cache contains an empty etag

Conflicts:
lib/files/cache/cache.php
tests/lib/files/cache/scanner.php

lib/files/cache/cache.php
lib/files/cache/scanner.php
tests/lib/files/cache/scanner.php

index 76e1ee977274643157235717701c4f052d1f214b..cb48ab446beda6abea4a575145ffb9a2cc71bdf1 100644 (file)
@@ -210,7 +210,6 @@ class Cache {
                        $data['path'] = $file;
                        $data['parent'] = $this->getParentId($file);
                        $data['name'] = basename($file);
-                       $data['encrypted'] = isset($data['encrypted']) ? ((int)$data['encrypted']) : 0;
 
                        list($queryParts, $params) = $this->buildParts($data);
                        $queryParts[] = '`storage`';
@@ -272,6 +271,9 @@ class Cache {
                                        $params[] = $this->getMimetypeId(substr($value, 0, strpos($value, '/')));
                                        $queryParts[] = '`mimepart`';
                                        $value = $this->getMimetypeId($value);
+                               } elseif ($name === 'encrypted') {
+                                       // Boolean to integer conversion
+                                       $value = $value ? 1 : 0;
                                }
                                $params[] = $value;
                                $queryParts[] = '`' . $name . '`';
index d99bd6e2ce0290950af4bb7d2ac573e1014ba88e..a87d98eb7b8b510a9d6b4d7d15136a12c6b7630c 100644 (file)
@@ -96,13 +96,34 @@ class Scanner extends BasicEmitter {
                                }
                                $newData = $data;
                                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
                                        if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) {
                                                if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
                                                        $data['size'] = $cacheData['size'];
                                                }
                                                if ($reuseExisting & self::REUSE_ETAG) {
-                                                       $data['etag'] = $cacheData['etag'];
+                                                       $data['etag'] = $etag;
+                                                       if ($propagateETagChange) {
+                                                               $parent = $file;
+                                                               while ($parent !== '') {
+                                                                       $parent = dirname($parent);
+                                                                       if ($parent === '.') {
+                                                                               $parent = '';
+                                                                       }
+                                                                       $parentCacheData = $this->cache->get($parent);
+                                                                       $this->cache->update($parentCacheData['fileid'], array(
+                                                                               'etag' => $this->storage->getETag($parent),
+                                                                       ));
+                                                               }
+                                                       }
                                                }
                                        }
                                        // Only update metadata that has changed
index 916ac449f29afa84630d86c97ee9182dd2a0ca8f..3f3a045377a8efba7351a4987f59dd749b748a99 100644 (file)
@@ -24,6 +24,21 @@ class Scanner extends \PHPUnit_Framework_TestCase {
         */
        private $cache;
 
+       function setUp() {
+               $this->storage = new \OC\Files\Storage\Temporary(array());
+               $this->scanner = new \OC\Files\Cache\Scanner($this->storage);
+               $this->cache = new \OC\Files\Cache\Cache($this->storage);
+       }
+
+       function tearDown() {
+               if ($this->cache) {
+                       $ids = $this->cache->getAll();
+                       $permissionsCache = $this->storage->getPermissionsCache();
+                       $permissionsCache->removeMultiple($ids, \OC_User::getUser());
+                       $this->cache->clear();
+               }
+       }
+
        function testFile() {
                $data = "dummy file data\n";
                $this->storage->file_put_contents('foo.txt', $data);
@@ -194,16 +209,28 @@ class Scanner extends \PHPUnit_Framework_TestCase {
                $this->assertFalse($this->cache->inCache('folder/bar.txt'));
        }
 
-       function setUp() {
-               $this->storage = new \OC\Files\Storage\Temporary(array());
-               $this->scanner = new \OC\Files\Cache\Scanner($this->storage);
-               $this->cache = new \OC\Files\Cache\Cache($this->storage);
-       }
+       public function testETagRecreation() {
+               $this->fillTestFolders();
 
-       function tearDown() {
-               $ids = $this->cache->getAll();
-               $permissionsCache = $this->storage->getPermissionsCache();
-               $permissionsCache->removeMultiple($ids, \OC_User::getUser());
-               $this->cache->clear();
+               $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);
+               $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('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']);
        }
 }