2012-10-03 13:24:49 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files\Cache;
|
2016-05-18 16:06:15 +03:00
|
|
|
|
2015-12-02 17:20:12 +03:00
|
|
|
use OC\Files\Cache\CacheEntry;
|
2012-10-03 13:24:49 +04:00
|
|
|
|
2015-11-03 03:52:41 +03:00
|
|
|
/**
|
2016-05-20 16:38:20 +03:00
|
|
|
* Class ScannerTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\Files\Cache
|
|
|
|
*/
|
2016-05-20 16:38:20 +03:00
|
|
|
class ScannerTest extends \Test\TestCase {
|
2012-10-03 13:24:49 +04:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Storage $storage
|
|
|
|
*/
|
|
|
|
private $storage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Cache\Scanner $scanner
|
|
|
|
*/
|
|
|
|
private $scanner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Cache\Cache $cache
|
|
|
|
*/
|
|
|
|
private $cache;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->storage = new \OC\Files\Storage\Temporary([]);
|
2013-09-23 14:45:02 +04:00
|
|
|
$this->scanner = new \OC\Files\Cache\Scanner($this->storage);
|
|
|
|
$this->cache = new \OC\Files\Cache\Cache($this->storage);
|
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2013-09-23 14:45:02 +04:00
|
|
|
if ($this->cache) {
|
|
|
|
$this->cache->clear();
|
|
|
|
}
|
2014-11-07 17:23:15 +03:00
|
|
|
|
|
|
|
parent::tearDown();
|
2013-09-23 14:45:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-03 13:24:49 +04:00
|
|
|
function testFile() {
|
|
|
|
$data = "dummy file data\n";
|
|
|
|
$this->storage->file_put_contents('foo.txt', $data);
|
|
|
|
$this->scanner->scanFile('foo.txt');
|
|
|
|
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
2012-10-03 13:24:49 +04:00
|
|
|
$cachedData = $this->cache->get('foo.txt');
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($cachedData['size'], strlen($data));
|
|
|
|
$this->assertEquals($cachedData['mimetype'], 'text/plain');
|
|
|
|
$this->assertNotEquals($cachedData['parent'], -1); //parent folders should be scanned automatically
|
2012-10-03 13:40:09 +04:00
|
|
|
|
2018-08-28 16:58:27 +03:00
|
|
|
$data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
|
2012-10-03 13:40:09 +04:00
|
|
|
$this->storage->file_put_contents('foo.png', $data);
|
|
|
|
$this->scanner->scanFile('foo.png');
|
|
|
|
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
2012-10-03 13:40:09 +04:00
|
|
|
$cachedData = $this->cache->get('foo.png');
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($cachedData['size'], strlen($data));
|
|
|
|
$this->assertEquals($cachedData['mimetype'], 'image/png');
|
2012-10-03 13:40:09 +04:00
|
|
|
}
|
|
|
|
|
2016-11-02 11:23:01 +03:00
|
|
|
function testFile4Byte() {
|
|
|
|
$data = "dummy file data\n";
|
|
|
|
$this->storage->file_put_contents('foo🙈.txt', $data);
|
|
|
|
|
|
|
|
if (\OC::$server->getDatabaseConnection()->supports4ByteText()) {
|
|
|
|
$this->assertNotNull($this->scanner->scanFile('foo🙈.txt'));
|
|
|
|
$this->assertTrue($this->cache->inCache('foo🙈.txt'), true);
|
|
|
|
|
|
|
|
$cachedData = $this->cache->get('foo🙈.txt');
|
|
|
|
$this->assertEquals(strlen($data), $cachedData['size']);
|
|
|
|
$this->assertEquals('text/plain', $cachedData['mimetype']);
|
|
|
|
$this->assertNotEquals(-1, $cachedData['parent']); //parent folders should be scanned automatically
|
|
|
|
} else {
|
|
|
|
$this->assertNull($this->scanner->scanFile('foo🙈.txt'));
|
|
|
|
$this->assertFalse($this->cache->inCache('foo🙈.txt'), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFileInvalidChars() {
|
|
|
|
$data = "dummy file data\n";
|
|
|
|
$this->storage->file_put_contents("foo\nbar.txt", $data);
|
|
|
|
|
|
|
|
$this->assertNull($this->scanner->scanFile("foo\nbar.txt"));
|
|
|
|
$this->assertFalse($this->cache->inCache("foo\nbar.txt"), true);
|
|
|
|
}
|
|
|
|
|
2012-10-03 15:07:19 +04:00
|
|
|
private function fillTestFolders() {
|
2012-10-03 13:40:09 +04:00
|
|
|
$textData = "dummy file data\n";
|
2018-08-28 16:58:27 +03:00
|
|
|
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
|
2012-10-03 15:07:19 +04:00
|
|
|
$this->storage->mkdir('folder');
|
2012-10-03 13:40:09 +04:00
|
|
|
$this->storage->file_put_contents('foo.txt', $textData);
|
|
|
|
$this->storage->file_put_contents('foo.png', $imgData);
|
2012-10-03 15:07:19 +04:00
|
|
|
$this->storage->file_put_contents('folder/bar.txt', $textData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFolder() {
|
|
|
|
$this->fillTestFolders();
|
2012-10-03 13:40:09 +04:00
|
|
|
|
|
|
|
$this->scanner->scan('');
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($this->cache->inCache(''), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('folder'), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('folder/bar.txt'), true);
|
2012-10-03 15:07:19 +04:00
|
|
|
|
|
|
|
$cachedDataText = $this->cache->get('foo.txt');
|
|
|
|
$cachedDataText2 = $this->cache->get('foo.txt');
|
|
|
|
$cachedDataImage = $this->cache->get('foo.png');
|
|
|
|
$cachedDataFolder = $this->cache->get('');
|
|
|
|
$cachedDataFolder2 = $this->cache->get('folder');
|
|
|
|
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($cachedDataImage['parent'], $cachedDataText['parent']);
|
|
|
|
$this->assertEquals($cachedDataFolder['fileid'], $cachedDataImage['parent']);
|
|
|
|
$this->assertEquals($cachedDataFolder['size'], $cachedDataImage['size'] + $cachedDataText['size'] + $cachedDataText2['size']);
|
|
|
|
$this->assertEquals($cachedDataFolder2['size'], $cachedDataText2['size']);
|
2012-10-03 15:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function testShallow() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals($this->cache->inCache(''), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('folder'), true);
|
|
|
|
$this->assertEquals($this->cache->inCache('folder/bar.txt'), false);
|
2012-10-03 15:07:19 +04:00
|
|
|
|
|
|
|
$cachedDataFolder = $this->cache->get('');
|
|
|
|
$cachedDataFolder2 = $this->cache->get('folder');
|
|
|
|
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertEquals(-1, $cachedDataFolder['size']);
|
|
|
|
$this->assertEquals(-1, $cachedDataFolder2['size']);
|
2012-10-03 20:19:45 +04:00
|
|
|
|
|
|
|
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
|
|
|
|
|
|
|
$cachedDataFolder2 = $this->cache->get('folder');
|
|
|
|
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertNotEquals($cachedDataFolder2['size'], -1);
|
2012-10-27 20:05:40 +04:00
|
|
|
|
2012-11-08 21:10:54 +04:00
|
|
|
$this->cache->correctFolderSize('folder');
|
2012-10-27 20:05:40 +04:00
|
|
|
|
|
|
|
$cachedDataFolder = $this->cache->get('');
|
2013-01-27 00:41:14 +04:00
|
|
|
$this->assertNotEquals($cachedDataFolder['size'], -1);
|
2012-10-03 13:24:49 +04:00
|
|
|
}
|
|
|
|
|
2013-06-17 20:03:57 +04:00
|
|
|
function testBackgroundScan() {
|
2012-11-22 02:18:58 +04:00
|
|
|
$this->fillTestFolders();
|
|
|
|
$this->storage->mkdir('folder2');
|
|
|
|
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
|
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/2bar.txt'));
|
|
|
|
$cachedData = $this->cache->get('');
|
|
|
|
$this->assertEquals(-1, $cachedData['size']);
|
|
|
|
|
|
|
|
$this->scanner->backgroundScan();
|
|
|
|
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
|
|
|
|
$cachedData = $this->cache->get('');
|
|
|
|
$this->assertnotEquals(-1, $cachedData['size']);
|
|
|
|
|
|
|
|
$this->assertFalse($this->cache->getIncomplete());
|
|
|
|
}
|
|
|
|
|
2016-05-18 16:06:15 +03:00
|
|
|
function testBackgroundScanOnlyRecurseIncomplete() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
$this->storage->mkdir('folder2');
|
|
|
|
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
|
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/2bar.txt'));
|
|
|
|
$this->assertFalse($this->cache->inCache('folder2/bar.txt'));
|
|
|
|
$this->cache->put('folder2', ['size' => 1]); // mark as complete
|
|
|
|
|
|
|
|
$cachedData = $this->cache->get('');
|
|
|
|
$this->assertEquals(-1, $cachedData['size']);
|
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE_INCOMPLETE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
|
|
|
|
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$this->assertFalse($this->cache->inCache('folder2/bar.txt'));
|
|
|
|
|
|
|
|
$cachedData = $this->cache->get('');
|
|
|
|
$this->assertNotEquals(-1, $cachedData['size']);
|
|
|
|
|
|
|
|
$this->assertFalse($this->cache->getIncomplete());
|
|
|
|
}
|
|
|
|
|
2019-03-02 01:52:58 +03:00
|
|
|
public function testBackgroundScanNestedIncompleteFolders() {
|
|
|
|
$this->storage->mkdir('folder');
|
|
|
|
$this->scanner->backgroundScan();
|
|
|
|
|
|
|
|
$this->storage->mkdir('folder/subfolder1');
|
|
|
|
$this->storage->mkdir('folder/subfolder2');
|
|
|
|
|
|
|
|
$this->storage->mkdir('folder/subfolder1/subfolder3');
|
|
|
|
$this->cache->put('folder', ['size' => -1]);
|
|
|
|
$this->cache->put('folder/subfolder1', ['size' => -1]);
|
|
|
|
|
|
|
|
// do a scan to get the folders into the cache.
|
|
|
|
$this->scanner->backgroundScan();
|
|
|
|
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/subfolder1/subfolder3'));
|
|
|
|
|
|
|
|
$this->storage->file_put_contents('folder/subfolder1/bar1.txt', 'foobar');
|
|
|
|
$this->storage->file_put_contents('folder/subfolder1/subfolder3/bar3.txt', 'foobar');
|
|
|
|
$this->storage->file_put_contents('folder/subfolder2/bar2.txt', 'foobar');
|
|
|
|
|
|
|
|
//mark folders as incomplete.
|
|
|
|
$this->cache->put('folder/subfolder1', ['size' => -1]);
|
|
|
|
$this->cache->put('folder/subfolder2', ['size' => -1]);
|
|
|
|
$this->cache->put('folder/subfolder1/subfolder3', ['size' => -1]);
|
|
|
|
|
|
|
|
$this->scanner->backgroundScan();
|
|
|
|
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/subfolder1/bar1.txt'));
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/subfolder2/bar2.txt'));
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/subfolder1/subfolder3/bar3.txt'));
|
|
|
|
|
|
|
|
//check if folder sizes are correct.
|
|
|
|
$this->assertEquals(18, $this->cache->get('folder')['size']);
|
|
|
|
$this->assertEquals(12, $this->cache->get('folder/subfolder1')['size']);
|
|
|
|
$this->assertEquals(6, $this->cache->get('folder/subfolder1/subfolder3')['size']);
|
|
|
|
$this->assertEquals(6, $this->cache->get('folder/subfolder2')['size']);
|
|
|
|
}
|
|
|
|
|
2013-06-17 20:03:57 +04:00
|
|
|
public function testReuseExisting() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
|
|
|
|
$this->scanner->scan('');
|
|
|
|
$oldData = $this->cache->get('');
|
|
|
|
$this->storage->unlink('folder/bar.txt');
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->cache->put('folder', ['mtime' => $this->storage->filemtime('folder'), 'storage_mtime' => $this->storage->filemtime('folder')]);
|
2013-06-17 20:03:57 +04:00
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE);
|
|
|
|
$newData = $this->cache->get('');
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->assertIsString($oldData['etag']);
|
|
|
|
$this->assertIsString($newData['etag']);
|
2014-02-27 12:39:34 +04:00
|
|
|
$this->assertNotSame($oldData['etag'], $newData['etag']);
|
2013-06-17 20:03:57 +04:00
|
|
|
$this->assertEquals($oldData['size'], $newData['size']);
|
|
|
|
|
|
|
|
$oldData = $newData;
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
|
|
|
|
$newData = $this->cache->get('');
|
2014-02-27 12:39:34 +04:00
|
|
|
$this->assertSame($oldData['etag'], $newData['etag']);
|
2013-06-17 20:03:57 +04:00
|
|
|
$this->assertEquals(-1, $newData['size']);
|
2013-08-12 17:37:15 +04:00
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
|
|
|
|
$oldData = $this->cache->get('');
|
|
|
|
$this->assertNotEquals(-1, $oldData['size']);
|
|
|
|
$this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
|
|
|
|
$newData = $this->cache->get('');
|
2014-02-27 12:39:34 +04:00
|
|
|
$this->assertSame($oldData['etag'], $newData['etag']);
|
2013-08-12 17:37:15 +04:00
|
|
|
$this->assertEquals($oldData['size'], $newData['size']);
|
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
|
|
|
|
$newData = $this->cache->get('');
|
2014-02-27 12:39:34 +04:00
|
|
|
$this->assertSame($oldData['etag'], $newData['etag']);
|
2013-08-12 17:37:15 +04:00
|
|
|
$this->assertEquals($oldData['size'], $newData['size']);
|
|
|
|
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
|
|
|
|
$newData = $this->cache->get('');
|
2014-02-27 12:39:34 +04:00
|
|
|
$this->assertSame($oldData['etag'], $newData['etag']);
|
2013-08-12 17:37:15 +04:00
|
|
|
$this->assertEquals($oldData['size'], $newData['size']);
|
2013-06-17 20:03:57 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 02:42:34 +04:00
|
|
|
public function testRemovedFile() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
|
|
|
|
$this->scanner->scan('');
|
|
|
|
$this->assertTrue($this->cache->inCache('foo.txt'));
|
|
|
|
$this->storage->unlink('foo.txt');
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
|
|
|
$this->assertFalse($this->cache->inCache('foo.txt'));
|
|
|
|
}
|
|
|
|
|
2013-06-20 12:47:37 +04:00
|
|
|
public function testRemovedFolder() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
|
|
|
|
$this->scanner->scan('');
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
2013-07-01 20:11:33 +04:00
|
|
|
$this->storage->rmdir('/folder');
|
2013-06-20 12:47:37 +04:00
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
|
|
|
$this->assertFalse($this->cache->inCache('folder'));
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
|
|
|
}
|
|
|
|
|
2014-06-10 17:26:18 +04:00
|
|
|
public function testScanRemovedFile() {
|
2013-08-06 17:59:06 +04:00
|
|
|
$this->fillTestFolders();
|
|
|
|
|
|
|
|
$this->scanner->scan('');
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$this->storage->unlink('folder/bar.txt');
|
|
|
|
$this->scanner->scanFile('folder/bar.txt');
|
|
|
|
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
|
|
|
}
|
|
|
|
|
2013-09-16 14:09:15 +04:00
|
|
|
public function testETagRecreation() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
|
2013-09-17 01:32:17 +04:00
|
|
|
$this->scanner->scan('folder/bar.txt');
|
2013-09-16 14:09:15 +04:00
|
|
|
|
|
|
|
// manipulate etag to simulate an empty etag
|
|
|
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
|
2015-12-02 17:20:12 +03:00
|
|
|
/** @var CacheEntry $data0 */
|
2013-09-17 01:32:17 +04:00
|
|
|
$data0 = $this->cache->get('folder/bar.txt');
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->assertIsString($data0['etag']);
|
2013-09-17 01:32:17 +04:00
|
|
|
$data1 = $this->cache->get('folder');
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->assertIsString($data1['etag']);
|
2013-09-17 01:32:17 +04:00
|
|
|
$data2 = $this->cache->get('');
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->assertIsString($data2['etag']);
|
2013-09-17 01:32:17 +04:00
|
|
|
$data0['etag'] = '';
|
2015-12-02 17:20:12 +03:00
|
|
|
$this->cache->put('folder/bar.txt', $data0->getData());
|
2013-09-16 14:09:15 +04:00
|
|
|
|
|
|
|
// rescan
|
2013-09-17 01:32:17 +04:00
|
|
|
$this->scanner->scan('folder/bar.txt', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
|
|
|
|
|
|
|
|
// verify cache content
|
|
|
|
$newData0 = $this->cache->get('folder/bar.txt');
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->assertIsString($newData0['etag']);
|
2014-02-27 12:39:34 +04:00
|
|
|
$this->assertNotEmpty($newData0['etag']);
|
2013-09-16 14:09:15 +04:00
|
|
|
}
|
2014-06-10 17:26:18 +04:00
|
|
|
|
|
|
|
public function testRepairParent() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
$this->scanner->scan('');
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$oldFolderId = $this->cache->getId('folder');
|
|
|
|
|
|
|
|
// delete the folder without removing the childs
|
|
|
|
$sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
|
2020-03-26 11:30:18 +03:00
|
|
|
\OC_DB::executeAudited($sql, [$oldFolderId]);
|
2014-06-10 17:26:18 +04:00
|
|
|
|
|
|
|
$cachedData = $this->cache->get('folder/bar.txt');
|
|
|
|
$this->assertEquals($oldFolderId, $cachedData['parent']);
|
|
|
|
$this->assertFalse($this->cache->inCache('folder'));
|
|
|
|
|
|
|
|
$this->scanner->scan('');
|
|
|
|
|
|
|
|
$this->assertTrue($this->cache->inCache('folder'));
|
|
|
|
$newFolderId = $this->cache->getId('folder');
|
|
|
|
$this->assertNotEquals($oldFolderId, $newFolderId);
|
|
|
|
|
|
|
|
$cachedData = $this->cache->get('folder/bar.txt');
|
|
|
|
$this->assertEquals($newFolderId, $cachedData['parent']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepairParentShallow() {
|
|
|
|
$this->fillTestFolders();
|
|
|
|
$this->scanner->scan('');
|
|
|
|
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
|
|
|
|
$oldFolderId = $this->cache->getId('folder');
|
|
|
|
|
|
|
|
// delete the folder without removing the childs
|
|
|
|
$sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
|
2020-03-26 11:30:18 +03:00
|
|
|
\OC_DB::executeAudited($sql, [$oldFolderId]);
|
2014-06-10 17:26:18 +04:00
|
|
|
|
|
|
|
$cachedData = $this->cache->get('folder/bar.txt');
|
|
|
|
$this->assertEquals($oldFolderId, $cachedData['parent']);
|
|
|
|
$this->assertFalse($this->cache->inCache('folder'));
|
|
|
|
|
|
|
|
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
|
|
|
|
|
|
|
$this->assertTrue($this->cache->inCache('folder'));
|
|
|
|
$newFolderId = $this->cache->getId('folder');
|
|
|
|
$this->assertNotEquals($oldFolderId, $newFolderId);
|
|
|
|
|
|
|
|
$cachedData = $this->cache->get('folder/bar.txt');
|
|
|
|
$this->assertEquals($newFolderId, $cachedData['parent']);
|
|
|
|
}
|
2015-10-12 14:59:16 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataTestIsPartialFile
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param bool $expected
|
|
|
|
*/
|
|
|
|
public function testIsPartialFile($path, $expected) {
|
|
|
|
$this->assertSame($expected,
|
|
|
|
$this->scanner->isPartialFile($path)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataTestIsPartialFile() {
|
|
|
|
return [
|
|
|
|
['foo.txt.part', true],
|
|
|
|
['/sub/folder/foo.txt.part', true],
|
|
|
|
['/sub/folder.part/foo.txt', true],
|
|
|
|
['foo.txt', false],
|
|
|
|
['/sub/folder/foo.txt', false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2012-10-03 13:24:49 +04:00
|
|
|
}
|