Skip to content

Commit

Permalink
Skip SharedStorage and FailedStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
IljaN committed Aug 16, 2018
1 parent 8bfd49d commit 6979a2c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/files/lib/Command/VerifyChecksums.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
namespace OCA\Files\Command;

use OC\Files\FileInfo;
use OC\Files\Storage\FailedStorage;
use OC\Files\Storage\Wrapper\Checksum;
use OCA\Files_Sharing\ISharedStorage;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -94,9 +96,19 @@ public function execute(InputInterface $input, OutputInterface $output) {
$path = $node->getInternalPath();
$currentChecksums = $node->getChecksum();
$owner = $node->getOwner()->getUID();
$storage = $node->getStorage();

if ($storage->instanceOfStorage(ISharedStorage::class) || $storage->instanceOfStorage(FailedStorage::class)) {
return;
}

if (!self::fileExistsOnDisk($node)) {
$output->writeln("Skipping $owner/$path => File is in file-cache but doesn`t exist on storage/disk", OutputInterface::VERBOSITY_VERBOSE);
$output->writeln("Skipping $owner/$path => File is in file-cache but doesn't exist on storage/disk", OutputInterface::VERBOSITY_VERBOSE);
return;
}

if (!$node->isReadable()) {
$output->writeln("Skipping $owner/$path => File not readable", OutputInterface::VERBOSITY_VERBOSE);
return;
}

Expand Down Expand Up @@ -188,7 +200,7 @@ private function updateChecksumsForNode(Node $node, $correctChecksum) {
* @return bool
*/
private static function fileExistsOnDisk(Node $node) {
$statResult = $node->stat();
$statResult = @$node->stat();
return \is_array($statResult) && isset($statResult['size']) && $statResult['size'] !== false;
}

Expand Down
60 changes: 60 additions & 0 deletions apps/files/tests/Command/VerifyChecksumsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use OC\Files\Storage\Wrapper\Checksum;
use OCA\Files\Command\VerifyChecksums;
use OCP\IUser;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;

Expand Down Expand Up @@ -270,6 +271,7 @@ public function testOnlyFilesInGivenPathArgumentAreRepaired() {
}

public function testOnlyFilesOfAGivenUserAreRepaired() {

/** @var File $file1 */
$file1 = $this->testFiles[0]['file'];
/** @var File $file2 */
Expand Down Expand Up @@ -299,4 +301,62 @@ public function testAllFilesCanBeRepaired() {

$this->assertChecksumsAreCorrect($this->testFiles);
}

public function testFileWithoutChecksumIsIgnored() {
/** @var File $file */
$file = $this->testFiles[0]['file'];
$file->getStorage()->getCache()->update(
$file->getId(),
['checksum' => '']
);

$this->cmd->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]);
$output = $this->cmd->getDisplay();

$this->assertContains('somefile.txt => No Checksum', $output);
$this->assertContains('Skipping', $output);
}

public function testFileInCacheButNotOnDiskIsIgnored() {
/** @var File $file */
$file = $this->testFiles[0]['file'];
$file->getStorage()->getCache()->update(
$file->getId(),
['path' => '/does/not/exist', 'name' => 'x-file.txt']
);

$this->cmd->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]);
$output = $this->cmd->getDisplay();

$this->assertContains('x-file.txt => File is in file-cache but doesn\'t exist on storage/disk', $output);
}

public function testInvalidArgs() {
$this->cmd->execute(['-p' => '/does/not/exist']);

$this->assertEquals(
VerifyChecksums::EXIT_INVALID_ARGS,
$this->cmd->getStatusCode(),
'Not existing path must return invalid args status code'
);

$this->cmd->execute(['-u' => 'doesnotexist@example.com']);

$this->assertEquals(
VerifyChecksums::EXIT_INVALID_ARGS,
$this->cmd->getStatusCode(),
'Not existing user must return invalid args status code'
);

$this->cmd->execute([
'-u' => 'foo@example.com',
'-p' => '/some/path'
]);

$this->assertEquals(
VerifyChecksums::EXIT_INVALID_ARGS,
$this->cmd->getStatusCode(),
'User and path must return invalid args status code when combined'
);
}
}

0 comments on commit 6979a2c

Please sign in to comment.