diff options
author | Robin Appelman <robin@icewind.nl> | 2021-01-26 20:24:30 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-01-27 16:11:23 +0100 |
commit | 68589f779212d4c78bc62dc0853b371ac75c6433 (patch) | |
tree | 10d7f7b8348636669efd72b52790230e0c840100 /apps | |
parent | 8bd39f081f52a5f2f4051db3743d49c200ef27c4 (diff) | |
download | nextcloud-server-68589f779212d4c78bc62dc0853b371ac75c6433.tar.gz nextcloud-server-68589f779212d4c78bc62dc0853b371ac75c6433.zip |
handle the cache where a cache entry with the correct path has already been recreated
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/lib/Command/RepairTree.php | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/apps/files/lib/Command/RepairTree.php b/apps/files/lib/Command/RepairTree.php index d021b59722c..1e4607dbe64 100644 --- a/apps/files/lib/Command/RepairTree.php +++ b/apps/files/lib/Command/RepairTree.php @@ -69,12 +69,18 @@ class RepairTree extends Command { $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(); + } } } @@ -85,6 +91,22 @@ class RepairTree extends Command { 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(); |