Skip to content

Commit

Permalink
When the scanner detects a file is changed clear checksum
Browse files Browse the repository at this point in the history
Fixes #23782 and #23783

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

* Unit test added
  • Loading branch information
rullzer committed Apr 19, 2016
1 parent 7186975 commit 0dbcbc4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/private/files/cache/scanner.php
Expand Up @@ -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'])) {
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/files/view.php
Expand Up @@ -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());
}
}

0 comments on commit 0dbcbc4

Please sign in to comment.