Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/files_trashbin/tests/TrashbinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ protected function tearDown() {
$this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER2 . '/files');
$this->rootView->deleteAll($this->trashRoot1);
$this->rootView->deleteAll($this->trashRoot2);
$this->rootView->mkdir(self::TEST_TRASHBIN_USER1 . '/files/');
$this->rootView->mkdir(self::TEST_TRASHBIN_USER2 . '/files/');

// clear trash table
$connection = \OC::$server->getDatabaseConnection();
Expand Down
2 changes: 2 additions & 0 deletions apps/files_versions/tests/VersioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ protected function tearDown() {
$this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files/');
$this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/');
$this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/');
$this->rootView->mkdir(self::TEST_VERSIONS_USER . '/files/');
$this->rootView->mkdir(self::TEST_VERSIONS_USER2 . '/files/');
}

\OC_Hook::clear();
Expand Down
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->getMock('\OC\Files\Storage\Storage');
$this->storage->method('getCache')->willReturn($this->getMock('\OCP\Files\Cache\ICache'));
$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);
}

}