From 8bfd49dafbfe7ca51175dfe9be3cff922a451ca1 Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Fri, 11 May 2018 14:27:01 +0200 Subject: [PATCH] - Ignore files which are deleted from disk - Show user to which the scanned file belongs --- apps/files/lib/Command/VerifyChecksums.php | 24 +++++++++++++++---- .../tests/Command/VerifyChecksumsTest.php | 6 ++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/files/lib/Command/VerifyChecksums.php b/apps/files/lib/Command/VerifyChecksums.php index 88757e24351b..b248fc912ea9 100644 --- a/apps/files/lib/Command/VerifyChecksums.php +++ b/apps/files/lib/Command/VerifyChecksums.php @@ -49,7 +49,6 @@ class VerifyChecksums extends Command { * @var IRootFolder */ private $rootFolder; - /** * @var IUserManager */ @@ -94,19 +93,24 @@ public function execute(InputInterface $input, OutputInterface $output) { $walkFunction = function (Node $node) use ($input, $output) { $path = $node->getInternalPath(); $currentChecksums = $node->getChecksum(); + $owner = $node->getOwner()->getUID(); + + if (!self::fileExistsOnDisk($node)) { + $output->writeln("Skipping $owner/$path => File is in file-cache but doesn`t exist on storage/disk", OutputInterface::VERBOSITY_VERBOSE); + return; + } // Files without calculated checksum can't cause checksum errors if (empty($currentChecksums)) { - $output->writeln("Skipping $path => No Checksum", OutputInterface::VERBOSITY_VERBOSE); + $output->writeln("Skipping $owner/$path => No Checksum", OutputInterface::VERBOSITY_VERBOSE); return; } - $output->writeln("Checking $path => $currentChecksums", OutputInterface::VERBOSITY_VERBOSE); + $output->writeln("Checking $owner/$path => $currentChecksums", OutputInterface::VERBOSITY_VERBOSE); $actualChecksums = self::calculateActualChecksums($path, $node->getStorage()); - if ($actualChecksums !== $currentChecksums) { $output->writeln( - "Mismatch for $path:\n Filecache:\t$currentChecksums\n Actual:\t$actualChecksums" + "Mismatch for $owner/$path:\n Filecache:\t$currentChecksums\n Actual:\t$actualChecksums" ); $this->exitStatus = self::EXIT_CHECKSUM_ERRORS; @@ -178,6 +182,16 @@ private function updateChecksumsForNode(Node $node, $correctChecksum) { ); } + /** + * + * @param Node $node + * @return bool + */ + private static function fileExistsOnDisk(Node $node) { + $statResult = $node->stat(); + return \is_array($statResult) && isset($statResult['size']) && $statResult['size'] !== false; + } + /** * @param $path * @param IStorage $storage diff --git a/apps/files/tests/Command/VerifyChecksumsTest.php b/apps/files/tests/Command/VerifyChecksumsTest.php index e6f178433360..ecb919834a23 100644 --- a/apps/files/tests/Command/VerifyChecksumsTest.php +++ b/apps/files/tests/Command/VerifyChecksumsTest.php @@ -90,7 +90,7 @@ private function createFileForUser($uid, $path, $content) { if (!empty($subDir)) { $currentDir = "$currentDir/$subDir"; if (!$userFolder->nodeExists($currentDir)) { - $userFolder->newFolder("$currentDir"); + $userFolder->newFolder($currentDir); } } } @@ -189,8 +189,8 @@ public function testFilesWithBrokenChecksumsAreDisplayed() { $output = $this->cmd->getDisplay(); - $this->assertContains("Mismatch for {$file1->getInternalPath()}", $output); - $this->assertContains("Mismatch for {$file2->getInternalPath()}", $output); + $this->assertContains($file1->getInternalPath(), $output); + $this->assertContains($file2->getInternalPath(), $output); $this->assertContains(self::BROKEN_CHECKSUM_STRING, $output); $this->assertContains($this->testFiles[4]['expectedChecksums'](), $output); $this->assertContains($this->testFiles[7]['expectedChecksums'](), $output);