Pārlūkot izejas kodu

Merge pull request #39044 from nextcloud/more-empty-mount-checking

Fix root mounts not being setup in some cases
Robin Appelman 6 mēneši atpakaļ
vecāks
revīzija
efe68d012c

+ 4 - 0
apps/files_sharing/lib/External/Manager.php

@@ -606,6 +606,10 @@ class Manager {
 			$this->logger->error('Mount point to remove share not found', ['mountPoint' => $mountPoint]);
 			return false;
 		}
+		if (!$mountPointObj instanceof Mount) {
+			$this->logger->error('Mount point to remove share is not an external share, share probably doesn\'t exist', ['mountPoint' => $mountPoint]);
+			return false;
+		}
 		$id = $mountPointObj->getStorage()->getCache()->getId('');
 
 		$mountPoint = $this->stripPath($mountPoint);

+ 10 - 3
apps/files_sharing/tests/External/ManagerTest.php

@@ -31,8 +31,10 @@
 namespace OCA\Files_Sharing\Tests\External;
 
 use OC\Federation\CloudIdManager;
+use OC\Files\Mount\MountPoint;
 use OC\Files\SetupManagerFactory;
 use OC\Files\Storage\StorageFactory;
+use OC\Files\Storage\Temporary;
 use OCA\Files_Sharing\External\Manager;
 use OCA\Files_Sharing\External\MountProvider;
 use OCA\Files_Sharing\Tests\TestCase;
@@ -191,13 +193,18 @@ class ManagerTest extends TestCase {
 	}
 
 	private function setupMounts() {
-		$this->mountManager->clear();
+		$this->clearMounts();
 		$mounts = $this->testMountProvider->getMountsForUser($this->user, new StorageFactory());
 		foreach ($mounts as $mount) {
 			$this->mountManager->addMount($mount);
 		}
 	}
 
+	private function clearMounts() {
+		$this->mountManager->clear();
+		$this->mountManager->addMount(new MountPoint(Temporary::class, '', []));
+	}
+
 	public function testAddUserShare() {
 		$this->doTestAddShare([
 			'remote' => 'http://localhost',
@@ -235,7 +242,7 @@ class ManagerTest extends TestCase {
 		if ($isGroup) {
 			$this->manager->expects($this->never())->method('tryOCMEndPoint');
 		} else {
-			$this->manager->expects($this->any())->method('tryOCMEndPoint')
+			$this->manager->method('tryOCMEndPoint')
 				->withConsecutive(
 					['http://localhost', 'token1', '2342', 'accept'],
 					['http://localhost', 'token3', '2342', 'decline'],
@@ -415,7 +422,7 @@ class ManagerTest extends TestCase {
 
 		$this->assertEmpty(self::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');
 
-		$this->mountManager->clear();
+		$this->clearMounts();
 		self::invokePrivate($this->manager, 'setupMounts');
 		$this->assertNotMount($shareData1['name']);
 		$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');

+ 5 - 0
lib/private/Files/Config/MountProviderCollection.php

@@ -238,6 +238,11 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
 		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
 			return array_merge($mounts, $providerMounts);
 		}, []);
+
+		if (count($mounts) === 0) {
+			throw new \Exception("No root mounts provided by any provider");
+		}
+
 		return $mounts;
 	}
 

+ 10 - 1
lib/private/Files/Mount/Manager.php

@@ -101,6 +101,15 @@ class Manager implements IMountManager {
 			return $this->pathCache[$path];
 		}
 
+
+
+		if (count($this->mounts) === 0) {
+			$this->setupManager->setupRoot();
+			if (count($this->mounts) === 0) {
+				throw new \Exception("No mounts even after explicitly setting up the root mounts");
+			}
+		}
+
 		$current = $path;
 		while (true) {
 			$mountPoint = $current . '/';
@@ -117,7 +126,7 @@ class Manager implements IMountManager {
 			}
 		}
 
-		throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
+		throw new NotFoundException("No mount for path " . $path . " existing mounts (" . count($this->mounts) ."): " . implode(",", array_keys($this->mounts)));
 	}
 
 	/**

+ 3 - 2
lib/private/Files/SetupManager.php

@@ -337,12 +337,13 @@ class SetupManager {
 		if ($this->rootSetup) {
 			return;
 		}
+
+		$this->setupBuiltinWrappers();
+
 		$this->rootSetup = true;
 
 		$this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
 
-		$this->setupBuiltinWrappers();
-
 		$rootMounts = $this->mountProviderCollection->getRootMounts();
 		foreach ($rootMounts as $rootMountProvider) {
 			$this->mountManager->addMount($rootMountProvider);