Skip to content

Commit

Permalink
Merge pull request #28504 from owncloud/stable10-scanner-detectmissin…
Browse files Browse the repository at this point in the history
…ghome

[stable10] Add extra check in case of missing home storage
  • Loading branch information
Vincent Petry authored Aug 8, 2017
2 parents 85fd5ce + f7874bf commit d59f7f8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ protected function getData($path) {
$data = $this->storage->getMetaData($path);
if (is_null($data)) {
\OCP\Util::writeLog('OC\Files\Cache\Scanner', "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG);
// Last Line of Defence against potential Metadata-loss
if ($this->storage->instanceOfStorage('\OCP\Files\IHomeStorage') && !$this->storage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage') && ($path === '' || $path === 'files')) {
\OCP\Util::writeLog('OC\Files\Cache\Scanner', 'Missing important folder "' . $path . '" in home storage!!! - ' . $this->storageId, \OCP\Util::ERROR);
throw new \OCP\Files\StorageNotAvailableException('Missing important folder "' . $path . '" in home storage - ' . $this->storageId);
}
}
return $data;
}
Expand Down
50 changes: 50 additions & 0 deletions tests/lib/Files/Cache/ScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,54 @@ public function dataTestIsPartialFile() {
];
}

public function failGetDataProvider() {
return [
// throws for empty path and "files" in home storage
[true, false, '', true],
[true, true, '', true],
[true, false, 'files', true],
[true, true, 'files', true],

// doesn't throw for federated shares (non-home)
[false, true, '', false],
[false, true, 'files', false],

// doesn't throw for external storage (non-home)
[false, false, '', false],
[false, false, 'files', false],

// doesn't throw for other paths
[true, false, 'other', false],

// doesn't throw if metadata exists
[true, false, 'other', false, []],
];
}

/**
* @dataProvider failGetDataProvider
*/
public function testFailGetData($isHomeStorage, $isSharedStorage, $scanPath, $expectedThrown, $metadata = null) {
$this->storage = $this->createMock(\OC\Files\Storage\Storage::class);
$this->storage->method('getCache')->willReturn($this->createMock(\OCP\Files\Cache\ICache::class));
$this->storage->expects($this->any())
->method('getMetaData')
->willReturn(null);
$this->storage->expects($this->any())
->method('instanceOfStorage')
->will($this->returnValueMap([
['\OCP\Files\IHomeStorage', $isHomeStorage],
['\OCA\Files_Sharing\ISharedStorage', $isSharedStorage],
]));
$this->scanner = new \OC\Files\Cache\Scanner($this->storage);
$thrown = false;
try {
$this->scanner->scanFile($scanPath);
} catch (\OCP\Files\StorageNotAvailableException $e) {
$thrown = true;
}

$this->assertEquals($expectedThrown, $thrown);
}

}

0 comments on commit d59f7f8

Please sign in to comment.