From 0dbcbc4cae2eb669fc73f60a761855a907469111 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 19 Apr 2016 17:01:34 +0200 Subject: [PATCH] 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 --- lib/private/files/cache/scanner.php | 2 ++ tests/lib/files/view.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 5ca32548fe0e..c16e8515b019 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -195,6 +195,8 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = $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'])) { diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 3e88a5306f89..86413c61aa11 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -2424,4 +2424,24 @@ public function testGetDirectoryContentMimeFilter($filter, $expected) { $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()); + } }