diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php index 961cea04fef6..eecff76f3025 100644 --- a/apps/files_trashbin/tests/TrashbinTest.php +++ b/apps/files_trashbin/tests/TrashbinTest.php @@ -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(); diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php index 2c206ff051f0..237ddd0b9b41 100644 --- a/apps/files_versions/tests/VersioningTest.php +++ b/apps/files_versions/tests/VersioningTest.php @@ -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(); diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index c17f9bfd51b4..dfe625a899a0 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -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; } diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index b44b6f5d0f54..8db220943049 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -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); + } + }