When the scanner detects a file is changed clear checksum

Fixes #23782 and #23783

If the file scanner detects a changed file we clear the checksum while
we update the cache.

* Unit test added
This commit is contained in:
Roeland Jago Douma 2016-04-19 17:01:34 +02:00
parent 98647b8fe4
commit 2296552104
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
2 changed files with 22 additions and 0 deletions

View File

@ -195,6 +195,8 @@ class Scanner extends BasicEmitter implements IScanner {
$fileId = -1;
}
if (!empty($newData)) {
// Reset the checksum if the data has changed
$newData['checksum'] = '';
$data['fileid'] = $this->addToCache($file, $newData, $fileId);
}
if (isset($cacheData['size'])) {

View File

@ -2424,4 +2424,24 @@ class View extends \Test\TestCase {
$this->assertEquals($expected, $files);
}
public function testFilePutContentsClearsChecksum() {
$storage = new Temporary(array());
$scanner = $storage->getScanner();
$storage->file_put_contents('foo.txt', 'bar');
\OC\Files\Filesystem::mount($storage, array(), '/test/');
$scanner->scan('');
$view = new \OC\Files\View('/test/foo.txt');
$view->putFileInfo('.', ['checksum' => '42']);
$this->assertEquals('bar', $view->file_get_contents(''));
$fh = tmpfile();
fwrite($fh, 'fooo');
rewind($fh);
$view->file_put_contents('', $fh);
$this->assertEquals('fooo', $view->file_get_contents(''));
$data = $view->getFileInfo('.');
$this->assertEquals('', $data->getChecksum());
}
}