Skip to content

Commit

Permalink
- Ignore files which are deleted from disk
Browse files Browse the repository at this point in the history
- Show user to which the scanned file belongs
  • Loading branch information
IljaN committed Aug 16, 2018
1 parent a87f912 commit 8bfd49d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 19 additions & 5 deletions apps/files/lib/Command/VerifyChecksums.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class VerifyChecksums extends Command {
* @var IRootFolder
*/
private $rootFolder;

/**
* @var IUserManager
*/
Expand Down Expand Up @@ -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(
"<info>Mismatch for $path:\n Filecache:\t$currentChecksums\n Actual:\t$actualChecksums</info>"
"<info>Mismatch for $owner/$path:\n Filecache:\t$currentChecksums\n Actual:\t$actualChecksums</info>"
);

$this->exitStatus = self::EXIT_CHECKSUM_ERRORS;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions apps/files/tests/Command/VerifyChecksumsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8bfd49d

Please sign in to comment.