recreate an etag within the scanner if the cache contains an empty etag
This commit is contained in:
parent
46f59b165e
commit
3c026b7cf6
2 changed files with 24 additions and 1 deletions
8
lib/files/cache/scanner.php
vendored
8
lib/files/cache/scanner.php
vendored
|
@ -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
|
||||
|
|
17
tests/lib/files/cache/scanner.php
vendored
17
tests/lib/files/cache/scanner.php
vendored
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue