Skip to content

Commit 03c7706

Browse files
committed
feat(files): Add support for storage-id and path in RepairTree command
This allows to run the command on specific part of the filecache. When the filecache is big, it prevents overloading the DB. Signed-off-by: Louis Chmn <[email protected]>
1 parent bae24eb commit 03c7706

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

apps/files/lib/Command/RepairTree.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCP\IDBConnection;
1212
use Symfony\Component\Console\Command\Command;
1313
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
class RepairTree extends Command {
@@ -26,11 +27,16 @@ protected function configure(): void {
2627
$this
2728
->setName('files:repair-tree')
2829
->setDescription('Try and repair malformed filesystem tree structures (may be necessary to run multiple times for nested malformations)')
29-
->addOption('dry-run');
30+
->addOption('dry-run')
31+
->addOption('storage-id', 's', InputOption::VALUE_OPTIONAL, 'If set, only repair files within the given storage ID', null)
32+
->addOption('path', 'p', InputOption::VALUE_OPTIONAL, 'If set, only repair files within the given path', null);
3033
}
3134

3235
public function execute(InputInterface $input, OutputInterface $output): int {
33-
$rows = $this->findBrokenTreeBits();
36+
$rows = $this->findBrokenTreeBits(
37+
$input->getOption('storage-id'),
38+
$input->getOption('path'),
39+
);
3440
$fix = !$input->getOption('dry-run');
3541

3642
$output->writeln('Found ' . count($rows) . ' file entries with an invalid path');
@@ -88,7 +94,7 @@ private function deleteById(int $fileId): void {
8894
$query->executeStatement();
8995
}
9096

91-
private function findBrokenTreeBits(): array {
97+
private function findBrokenTreeBits(string|null $storageId, string|null $path): array {
9298
$query = $this->connection->getQueryBuilder();
9399

94100
$query->select('f.fileid', 'f.path', 'f.parent', 'f.name')
@@ -108,6 +114,14 @@ private function findBrokenTreeBits(): array {
108114
$query->expr()->neq('f.storage', 'p.storage')
109115
));
110116

117+
if ($storageId !== null) {
118+
$query->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId)));
119+
}
120+
121+
if ($path !== null) {
122+
$query->andWhere($query->expr()->like('f.path', $query->createNamedParameter($path . '%')));
123+
}
124+
111125
return $query->executeQuery()->fetchAllAssociative();
112126
}
113127
}

0 commit comments

Comments
 (0)