From a7e371520ffd023356497da5010c6b30ab79146a Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 9 Nov 2018 15:58:08 +0100 Subject: [PATCH] File cache hole check only report storage id once Fix file cache repair check to only output the storage id once instead of multiple times. --- .../Repair/RepairMismatchFileCachePath.php | 6 ++++-- .../Repair/RepairMismatchFileCachePathTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/private/Repair/RepairMismatchFileCachePath.php b/lib/private/Repair/RepairMismatchFileCachePath.php index c0229e8951a5..e90fb9a1ce72 100644 --- a/lib/private/Repair/RepairMismatchFileCachePath.php +++ b/lib/private/Repair/RepairMismatchFileCachePath.php @@ -243,9 +243,10 @@ private function reportAffectedStoragesParentIdWrongPath(IOutput $out) { $storageIds = []; foreach ($rows as $row) { - $storageIds[] = $row['storage']; + $storageIds[$row['storage']] = true; } + $storageIds = \array_keys($storageIds); if (!empty($storageIds)) { $out->warning('The file cache contains entries with invalid path values for the following storage numeric ids: ' . \implode(' ', $storageIds)); $out->warning('Please run `occ files:scan --all --repair` to repair' @@ -271,9 +272,10 @@ private function reportAffectedStoragesNonExistingParentIdEntry(IOutput $out) { $storageIds = []; foreach ($rows as $row) { - $storageIds[] = $row['storage']; + $storageIds[$row['storage']] = true; } + $storageIds = \array_keys($storageIds); if (!empty($storageIds)) { $out->warning('The file cache contains entries where the parent id does not point to any existing entry for the following storage numeric ids: ' . \implode(' ', $storageIds)); $out->warning('Please run `occ files:scan --all --repair` to repair all affected storages'); diff --git a/tests/lib/Repair/RepairMismatchFileCachePathTest.php b/tests/lib/Repair/RepairMismatchFileCachePathTest.php index 2f1d58b3d47a..fa8cf9d8f628 100644 --- a/tests/lib/Repair/RepairMismatchFileCachePathTest.php +++ b/tests/lib/Repair/RepairMismatchFileCachePathTest.php @@ -216,6 +216,15 @@ public function testRepairEntry($sourceStorageId, $targetStorageId, $targetDir, ->method('getSystemValue') ->with('version', '0.0.0') ->willReturn('10.0.3'); + + // test report command first + $this->repair->setCountOnly(true); + $outputMock->expects($this->at(0)) + ->method('warning') + ->with($this->logicalAnd($this->stringContains('with invalid path values'), $this->stringContains($sourceStorageId))); + $this->repair->run($outputMock); + $this->repair->setCountOnly(false); + if ($repairStoragesOrder === null) { // no storage selected, full repair $this->repair->setStorageNumericId(null); @@ -552,6 +561,13 @@ public function testRepairParentIdPointingNowhere() { ->method('getSystemValue') ->with('version', '0.0.0') ->willReturn('10.0.3'); + + $this->repair->setCountOnly(true); + $outputMock->expects($this->at(0)) + ->method('warning') + ->with($this->logicalAnd($this->stringContains('parent id does not point'), $this->stringContains($storageId))); + $this->repair->run($outputMock); + $this->repair->setCountOnly(false); $this->repair->run($outputMock); // wrong parent root reparented to actual root