aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-16 12:09:15 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-16 12:09:15 +0200
commit3c026b7cf601c0b83dd02436f17714fcf48cb9a8 (patch)
treecf6f5f0fc9d454cb91d47996df92b08d11cd7230
parent46f59b165e5bd1908509e8a62b67bf983cfd6224 (diff)
downloadnextcloud-server-3c026b7cf601c0b83dd02436f17714fcf48cb9a8.tar.gz
nextcloud-server-3c026b7cf601c0b83dd02436f17714fcf48cb9a8.zip
recreate an etag within the scanner if the cache contains an empty etag
-rw-r--r--lib/files/cache/scanner.php8
-rw-r--r--tests/lib/files/cache/scanner.php17
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 9d180820e9d..78cab6ed2da 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -97,13 +97,19 @@ class Scanner extends BasicEmitter {
}
$newData = $data;
if ($reuseExisting and $cacheData = $this->cache->get($file)) {
+ // prevent empty etag
+ $etag = $cacheData['etag'];
+ if (empty($etag)) {
+ $etag = $data['etag'];
+ }
+
// 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;
}
}
// Only update metadata that has changed
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
index f6deb93a49e..fa1b3406040 100644
--- a/tests/lib/files/cache/scanner.php
+++ b/tests/lib/files/cache/scanner.php
@@ -184,6 +184,23 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
}
+ public function testETagRecreation() {
+ $this->fillTestFolders();
+
+ $this->scanner->scan('');
+
+ // 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);
+
+ // rescan
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
+ $newData = $this->cache->get('');
+ $this->assertNotEmpty($newData['etag']);
+
+ }
+
function setUp() {
$this->storage = new \OC\Files\Storage\Temporary(array());
$this->scanner = new \OC\Files\Cache\Scanner($this->storage);