Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle the cache where a cache entry with the correct path has alread…
…y been recreated

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and backportbot[bot] committed Apr 19, 2021
commit f8346f43f136a060e6938f157338570b60363e97
34 changes: 28 additions & 6 deletions apps/files/lib/Command/RepairTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,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 +91,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