Merge pull request #8968 from owncloud/scanner-parent-repair
Repair broken parent link in the scanner
This commit is contained in:
commit
b595c982d0
|
@ -89,10 +89,9 @@ class Scanner extends BasicEmitter {
|
|||
*
|
||||
* @param string $file
|
||||
* @param int $reuseExisting
|
||||
* @param bool $parentExistsInCache
|
||||
* @return array an array of metadata of the scanned file
|
||||
*/
|
||||
public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) {
|
||||
public function scanFile($file, $reuseExisting = 0) {
|
||||
if (!self::isPartialFile($file)
|
||||
and !Filesystem::isFileBlacklisted($file)
|
||||
) {
|
||||
|
@ -100,19 +99,22 @@ class Scanner extends BasicEmitter {
|
|||
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
|
||||
$data = $this->getData($file);
|
||||
if ($data) {
|
||||
if ($file and !$parentExistsInCache) {
|
||||
$parent = dirname($file);
|
||||
if ($parent === '.' or $parent === '/') {
|
||||
$parent = '';
|
||||
}
|
||||
if (!$this->cache->inCache($parent)) {
|
||||
$this->scanFile($parent);
|
||||
$parentId = $this->cache->getId($parent);
|
||||
|
||||
// scan the parent if it's not in the cache (id -1) and the current file is not the root folder
|
||||
if ($file and $parentId === -1) {
|
||||
$parentData = $this->scanFile($parent);
|
||||
$parentId = $parentData['fileid'];
|
||||
}
|
||||
if ($parent) {
|
||||
$data['parent'] = $parentId;
|
||||
}
|
||||
$newData = $data;
|
||||
$cacheData = $this->cache->get($file);
|
||||
if ($cacheData) {
|
||||
if ($reuseExisting) {
|
||||
if ($cacheData and $reuseExisting) {
|
||||
// prevent empty etag
|
||||
if (empty($cacheData['etag'])) {
|
||||
$etag = $data['etag'];
|
||||
|
@ -138,7 +140,8 @@ class Scanner extends BasicEmitter {
|
|||
"!!! No reuse of etag for '$file' !!! \ncache: $cacheDataString \ndata: $dataString",
|
||||
\OCP\Util::DEBUG);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$newData = $data;
|
||||
}
|
||||
if (!empty($newData)) {
|
||||
$data['fileid'] = $this->addToCache($file, $newData);
|
||||
|
@ -238,7 +241,7 @@ class Scanner extends BasicEmitter {
|
|||
if (!Filesystem::isIgnoredDir($file)) {
|
||||
$newChildren[] = $file;
|
||||
try {
|
||||
$data = $this->scanFile($child, $reuse, true);
|
||||
$data = $this->scanFile($child, $reuse);
|
||||
if ($data) {
|
||||
if ($data['mimetype'] === 'httpd/unix-directory' and $recursive === self::SCAN_RECURSIVE) {
|
||||
$childQueue[] = $child;
|
||||
|
|
|
@ -32,7 +32,6 @@ class Scanner extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
function tearDown() {
|
||||
if ($this->cache) {
|
||||
$ids = $this->cache->getAll();
|
||||
$this->cache->clear();
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +198,7 @@ class Scanner extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
|
||||
}
|
||||
|
||||
public function testScanRemovedFile(){
|
||||
public function testScanRemovedFile() {
|
||||
$this->fillTestFolders();
|
||||
|
||||
$this->scanner->scan('');
|
||||
|
@ -233,4 +232,52 @@ class Scanner extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertInternalType('string', $newData0['etag']);
|
||||
$this->assertNotEmpty($newData0['etag']);
|
||||
}
|
||||
|
||||
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` = ?';
|
||||
\OC_DB::executeAudited($sql, array($oldFolderId));
|
||||
|
||||
$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` = ?';
|
||||
\OC_DB::executeAudited($sql, array($oldFolderId));
|
||||
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue