Browse Source

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
tags/v9.1.0beta1
Roeland Jago Douma 8 years ago
parent
commit
0dbcbc4cae
No account linked to committer's email address
2 changed files with 22 additions and 0 deletions
  1. 2
    0
      lib/private/files/cache/scanner.php
  2. 20
    0
      tests/lib/files/view.php

+ 2
- 0
lib/private/files/cache/scanner.php 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'])) {

+ 20
- 0
tests/lib/files/view.php 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());
}
}

Loading…
Cancel
Save