Skip to content

Commit ef9f205

Browse files
committed
handle the cache where a cache entry with the correct path has already been recreated
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 3558abd commit ef9f205

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

apps/files/lib/Command/RepairTree.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,18 @@ public function execute(InputInterface $input, OutputInterface $output): int {
6969
$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);
7070

7171
if ($fix) {
72-
$query->setParameters([
73-
'fileid' => $row['fileid'],
74-
'path' => $row['parent_path'] . '/' . $row['name'],
75-
'storage' => $row['parent_storage'],
76-
]);
77-
$query->execute();
72+
$fileId = $this->getFileId($row['parent_storage'], $row['parent_path'] . '/' . $row['name']);
73+
if ($fileId > 0) {
74+
$output->writeln("Cache entry has already be recreated with id $fileId, deleting instead");
75+
$this->deleteById($row['fileid']);
76+
} else {
77+
$query->setParameters([
78+
'fileid' => $row['fileid'],
79+
'path' => $row['parent_path'] . '/' . $row['name'],
80+
'storage' => $row['parent_storage'],
81+
]);
82+
$query->execute();
83+
}
7884
}
7985
}
8086

@@ -85,6 +91,22 @@ public function execute(InputInterface $input, OutputInterface $output): int {
8591
return 0;
8692
}
8793

94+
private function getFileId(int $storage, string $path) {
95+
$query = $this->connection->getQueryBuilder();
96+
$query->select('fileid')
97+
->from('filecache')
98+
->where($query->expr()->eq('storage', $query->createNamedParameter($storage)))
99+
->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5($path))));
100+
return $query->execute()->fetch(\PDO::FETCH_COLUMN);
101+
}
102+
103+
private function deleteById(int $fileId) {
104+
$query = $this->connection->getQueryBuilder();
105+
$query->delete('filecache')
106+
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId)));
107+
$query->execute();
108+
}
109+
88110
private function findBrokenTreeBits(): array {
89111
$query = $this->connection->getQueryBuilder();
90112

0 commit comments

Comments
 (0)