Skip to content

Commit

Permalink
handle the cache where a cache entry with the correct path has alread…
Browse files Browse the repository at this point in the history
…y been recreated

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jan 26, 2021
1 parent 3558abd commit 9884fc2
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions apps/files/lib/Command/RepairTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Files\Command;

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -69,12 +70,18 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$output->writeln("Path of file ${row['fileid']} is ${row['path']} but should be ${row['parent_path']}/${row['name']} based on it's parent", OutputInterface::VERBOSITY_VERBOSE);

if ($fix) {
$query->setParameters([
'fileid' => $row['fileid'],
'path' => $row['parent_path'] . '/' . $row['name'],
'storage' => $row['parent_storage'],
]);
$query->execute();
$fileId = $this->getFileId($row['parent_storage'], $row['parent_path'] . '/' . $row['name']);
if ($fileId > 0) {
$output->writeln("Cache entry has already be recreated with id $fileId, deleting instead");
$this->deleteById($row['fileid']);
} else {
$query->setParameters([
'fileid' => $row['fileid'],
'path' => $row['parent_path'] . '/' . $row['name'],
'storage' => $row['parent_storage'],
]);
$query->execute();
}
}
}

Expand All @@ -85,6 +92,22 @@ public function execute(InputInterface $input, OutputInterface $output): int {
return 0;
}

private function getFileId(int $storage, string $path) {
$query = $this->connection->getQueryBuilder();
$query->select('fileid')
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($storage)))
->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5($path))));
return $query->execute()->fetch(\PDO::FETCH_COLUMN);
}

private function deleteById(int $fileId) {
$query = $this->connection->getQueryBuilder();
$query->delete('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId)));
$query->execute();
}

private function findBrokenTreeBits(): array {
$query = $this->connection->getQueryBuilder();

Expand Down

0 comments on commit 9884fc2

Please sign in to comment.