etag changes are now propagated up the file tree

This commit is contained in:
Thomas Müller 2013-09-16 23:32:17 +02:00
parent 3b42ac8eb6
commit c8f9efeb94
2 changed files with 29 additions and 6 deletions

View File

@ -99,8 +99,10 @@ class Scanner extends BasicEmitter {
if ($reuseExisting and $cacheData = $this->cache->get($file)) { if ($reuseExisting and $cacheData = $this->cache->get($file)) {
// prevent empty etag // prevent empty etag
$etag = $cacheData['etag']; $etag = $cacheData['etag'];
$propagateETagChange = false;
if (empty($etag)) { if (empty($etag)) {
$etag = $data['etag']; $etag = $data['etag'];
$propagateETagChange = true;
} }
// only reuse data if the file hasn't explicitly changed // only reuse data if the file hasn't explicitly changed
@ -110,6 +112,18 @@ class Scanner extends BasicEmitter {
} }
if ($reuseExisting & self::REUSE_ETAG) { if ($reuseExisting & self::REUSE_ETAG) {
$data['etag'] = $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 // Only update metadata that has changed

View File

@ -187,17 +187,26 @@ class Scanner extends \PHPUnit_Framework_TestCase {
public function testETagRecreation() { public function testETagRecreation() {
$this->fillTestFolders(); $this->fillTestFolders();
$this->scanner->scan(''); $this->scanner->scan('folder/bar.txt');
// manipulate etag to simulate an empty etag // manipulate etag to simulate an empty etag
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
$data['etag'] = ''; $data0 = $this->cache->get('folder/bar.txt');
$this->cache->put('', $data); $data1 = $this->cache->get('folder');
$data2 = $this->cache->get('');
$data0['etag'] = '';
$this->cache->put('folder/bar.txt', $data0);
// rescan // rescan
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG); $this->scanner->scan('folder/bar.txt', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
$newData = $this->cache->get('');
$this->assertNotEmpty($newData['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']);
} }