Also repair storage id's when repairing invalid entries
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
fad8b275f1
commit
9c2dce34e9
|
@ -332,7 +332,7 @@ class Cache implements ICache {
|
||||||
protected function buildParts(array $data) {
|
protected function buildParts(array $data) {
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
|
'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
|
||||||
'etag', 'permissions', 'checksum');
|
'etag', 'permissions', 'checksum', 'storage');
|
||||||
|
|
||||||
$doNotCopyStorageMTime = false;
|
$doNotCopyStorageMTime = false;
|
||||||
if (array_key_exists('mtime', $data) && $data['mtime'] === null) {
|
if (array_key_exists('mtime', $data) && $data['mtime'] === null) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ class RepairInvalidPaths implements IRepairStep {
|
||||||
);
|
);
|
||||||
|
|
||||||
//select f.path, f.parent,p.path from oc_filecache f inner join oc_filecache p on f.parent=p.fileid and p.path!='' where f.path != p.path || '/' || f.name;
|
//select f.path, f.parent,p.path from oc_filecache f inner join oc_filecache p on f.parent=p.fileid and p.path!='' where f.path != p.path || '/' || f.name;
|
||||||
$query = $builder->select('f.fileid', 'f.path', 'p.path AS parent_path', 'f.name', 'f.parent', 'f.storage')
|
$query = $builder->select('f.fileid', 'f.path', 'p.path AS parent_path', 'f.name', 'f.parent', 'f.storage', 'p.storage as parent_storage')
|
||||||
->from('filecache', 'f')
|
->from('filecache', 'f')
|
||||||
->innerJoin('f', 'filecache', 'p', $builder->expr()->andX(
|
->innerJoin('f', 'filecache', 'p', $builder->expr()->andX(
|
||||||
$builder->expr()->eq('f.parent', 'p.fileid'),
|
$builder->expr()->eq('f.parent', 'p.fileid'),
|
||||||
|
@ -95,17 +95,19 @@ class RepairInvalidPaths implements IRepairStep {
|
||||||
return $this->getIdQuery->execute()->fetchColumn();
|
return $this->getIdQuery->execute()->fetchColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function update($fileid, $newPath) {
|
private function update($fileid, $newPath, $newStorage) {
|
||||||
if (!$this->updateQuery) {
|
if (!$this->updateQuery) {
|
||||||
$builder = $this->connection->getQueryBuilder();
|
$builder = $this->connection->getQueryBuilder();
|
||||||
|
|
||||||
$this->updateQuery = $builder->update('filecache')
|
$this->updateQuery = $builder->update('filecache')
|
||||||
->set('path', $builder->createParameter('newpath'))
|
->set('path', $builder->createParameter('newpath'))
|
||||||
->set('path_hash', $builder->func()->md5($builder->createParameter('newpath')))
|
->set('path_hash', $builder->func()->md5($builder->createParameter('newpath')))
|
||||||
|
->set('storage', $builder->createParameter('newstorage'))
|
||||||
->where($builder->expr()->eq('fileid', $builder->createParameter('fileid')));
|
->where($builder->expr()->eq('fileid', $builder->createParameter('fileid')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updateQuery->setParameter('newpath', $newPath);
|
$this->updateQuery->setParameter('newpath', $newPath);
|
||||||
|
$this->updateQuery->setParameter('newstorage', $newStorage);
|
||||||
$this->updateQuery->setParameter('fileid', $fileid, IQueryBuilder::PARAM_INT);
|
$this->updateQuery->setParameter('fileid', $fileid, IQueryBuilder::PARAM_INT);
|
||||||
|
|
||||||
$this->updateQuery->execute();
|
$this->updateQuery->execute();
|
||||||
|
@ -146,12 +148,12 @@ class RepairInvalidPaths implements IRepairStep {
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$count++;
|
$count++;
|
||||||
$calculatedPath = $entry['parent_path'] . '/' . $entry['name'];
|
$calculatedPath = $entry['parent_path'] . '/' . $entry['name'];
|
||||||
if ($newId = $this->getId($entry['storage'], $calculatedPath)) {
|
if ($newId = $this->getId($entry['parent_storage'], $calculatedPath)) {
|
||||||
// a new entry with the correct path has already been created, reuse that one and delete the incorrect entry
|
// a new entry with the correct path has already been created, reuse that one and delete the incorrect entry
|
||||||
$this->reparent($entry['fileid'], $newId);
|
$this->reparent($entry['fileid'], $newId);
|
||||||
$this->delete($entry['fileid']);
|
$this->delete($entry['fileid']);
|
||||||
} else {
|
} else {
|
||||||
$this->update($entry['fileid'], $calculatedPath);
|
$this->update($entry['fileid'], $calculatedPath, $entry['parent_storage']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->connection->commit();
|
$this->connection->commit();
|
||||||
|
|
|
@ -36,6 +36,10 @@ class RepairInvalidPathsTest extends TestCase {
|
||||||
private $storage;
|
private $storage;
|
||||||
/** @var Cache */
|
/** @var Cache */
|
||||||
private $cache;
|
private $cache;
|
||||||
|
/** @var Temporary */
|
||||||
|
private $storage2;
|
||||||
|
/** @var Cache */
|
||||||
|
private $cache2;
|
||||||
/** @var RepairInvalidPaths */
|
/** @var RepairInvalidPaths */
|
||||||
private $repair;
|
private $repair;
|
||||||
|
|
||||||
|
@ -44,6 +48,8 @@ class RepairInvalidPathsTest extends TestCase {
|
||||||
|
|
||||||
$this->storage = new Temporary();
|
$this->storage = new Temporary();
|
||||||
$this->cache = $this->storage->getCache();
|
$this->cache = $this->storage->getCache();
|
||||||
|
$this->storage2 = new Temporary();
|
||||||
|
$this->cache2 = $this->storage2->getCache();
|
||||||
$config = $this->createMock(IConfig::class);
|
$config = $this->createMock(IConfig::class);
|
||||||
$config->expects($this->any())
|
$config->expects($this->any())
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
|
@ -152,4 +158,32 @@ class RepairInvalidPathsTest extends TestCase {
|
||||||
$this->assertEquals($folderId1, $this->cache->getId('foo2/bar'));
|
$this->assertEquals($folderId1, $this->cache->getId('foo2/bar'));
|
||||||
$this->assertEquals($folderId2, $this->cache->getId('foo2/bar2'));
|
$this->assertEquals($folderId2, $this->cache->getId('foo2/bar2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRepairNonDuplicateBetweenStorage() {
|
||||||
|
$this->storage->mkdir('foo/bar/asd');
|
||||||
|
$this->storage2->mkdir('foo2');
|
||||||
|
$this->storage->getScanner()->scan('');
|
||||||
|
$this->storage2->getScanner()->scan('');
|
||||||
|
|
||||||
|
$folderId = $this->cache->getId('foo/bar');
|
||||||
|
$newParentEntry = $this->cache2->get('foo2');
|
||||||
|
$newParentFolderId = $newParentEntry->getId();
|
||||||
|
// failed rename, moved entry is updated but not it's children
|
||||||
|
$this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId, 'storage' => $newParentEntry->getStorageId()]);
|
||||||
|
|
||||||
|
$this->assertTrue($this->cache2->inCache('foo2/bar'));
|
||||||
|
$this->assertTrue($this->cache->inCache('foo/bar/asd'));
|
||||||
|
$this->assertFalse($this->cache2->inCache('foo2/bar/asd'));
|
||||||
|
|
||||||
|
$this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']);
|
||||||
|
|
||||||
|
$this->repair->run($this->createMock(IOutput::class));
|
||||||
|
|
||||||
|
$this->assertTrue($this->cache2->inCache('foo2/bar'));
|
||||||
|
$this->assertTrue($this->cache2->inCache('foo2/bar/asd'));
|
||||||
|
$this->assertFalse($this->cache->inCache('foo/bar/asd'));
|
||||||
|
|
||||||
|
$this->assertEquals($folderId, $this->cache2->get('foo2/bar/asd')['parent']);
|
||||||
|
$this->assertEquals($folderId, $this->cache2->getId('foo2/bar'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue