Skip to content

Commit efe68d0

Browse files
authored
Merge pull request #39044 from nextcloud/more-empty-mount-checking
Fix root mounts not being setup in some cases
2 parents 970ac3d + 1eb3293 commit efe68d0

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

apps/files_sharing/lib/External/Manager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ public function removeShare($mountPoint): bool {
606606
$this->logger->error('Mount point to remove share not found', ['mountPoint' => $mountPoint]);
607607
return false;
608608
}
609+
if (!$mountPointObj instanceof Mount) {
610+
$this->logger->error('Mount point to remove share is not an external share, share probably doesn\'t exist', ['mountPoint' => $mountPoint]);
611+
return false;
612+
}
609613
$id = $mountPointObj->getStorage()->getCache()->getId('');
610614

611615
$mountPoint = $this->stripPath($mountPoint);

apps/files_sharing/tests/External/ManagerTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
namespace OCA\Files_Sharing\Tests\External;
3232

3333
use OC\Federation\CloudIdManager;
34+
use OC\Files\Mount\MountPoint;
3435
use OC\Files\SetupManagerFactory;
3536
use OC\Files\Storage\StorageFactory;
37+
use OC\Files\Storage\Temporary;
3638
use OCA\Files_Sharing\External\Manager;
3739
use OCA\Files_Sharing\External\MountProvider;
3840
use OCA\Files_Sharing\Tests\TestCase;
@@ -191,13 +193,18 @@ private function createManagerForUser($userId) {
191193
}
192194

193195
private function setupMounts() {
194-
$this->mountManager->clear();
196+
$this->clearMounts();
195197
$mounts = $this->testMountProvider->getMountsForUser($this->user, new StorageFactory());
196198
foreach ($mounts as $mount) {
197199
$this->mountManager->addMount($mount);
198200
}
199201
}
200202

203+
private function clearMounts() {
204+
$this->mountManager->clear();
205+
$this->mountManager->addMount(new MountPoint(Temporary::class, '', []));
206+
}
207+
201208
public function testAddUserShare() {
202209
$this->doTestAddShare([
203210
'remote' => 'http://localhost',
@@ -235,7 +242,7 @@ public function doTestAddShare($shareData1, $isGroup = false) {
235242
if ($isGroup) {
236243
$this->manager->expects($this->never())->method('tryOCMEndPoint');
237244
} else {
238-
$this->manager->expects($this->any())->method('tryOCMEndPoint')
245+
$this->manager->method('tryOCMEndPoint')
239246
->withConsecutive(
240247
['http://localhost', 'token1', '2342', 'accept'],
241248
['http://localhost', 'token3', '2342', 'decline'],
@@ -415,7 +422,7 @@ public function doTestAddShare($shareData1, $isGroup = false) {
415422

416423
$this->assertEmpty(self::invokePrivate($this->manager, 'getShares', [null]), 'Asserting all shares for the user have been deleted');
417424

418-
$this->mountManager->clear();
425+
$this->clearMounts();
419426
self::invokePrivate($this->manager, 'setupMounts');
420427
$this->assertNotMount($shareData1['name']);
421428
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');

lib/private/Files/Config/MountProviderCollection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ public function getRootMounts(): array {
238238
$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
239239
return array_merge($mounts, $providerMounts);
240240
}, []);
241+
242+
if (count($mounts) === 0) {
243+
throw new \Exception("No root mounts provided by any provider");
244+
}
245+
241246
return $mounts;
242247
}
243248

lib/private/Files/Mount/Manager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public function find(string $path): IMountPoint {
101101
return $this->pathCache[$path];
102102
}
103103

104+
105+
106+
if (count($this->mounts) === 0) {
107+
$this->setupManager->setupRoot();
108+
if (count($this->mounts) === 0) {
109+
throw new \Exception("No mounts even after explicitly setting up the root mounts");
110+
}
111+
}
112+
104113
$current = $path;
105114
while (true) {
106115
$mountPoint = $current . '/';
@@ -117,7 +126,7 @@ public function find(string $path): IMountPoint {
117126
}
118127
}
119128

120-
throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
129+
throw new NotFoundException("No mount for path " . $path . " existing mounts (" . count($this->mounts) ."): " . implode(",", array_keys($this->mounts)));
121130
}
122131

123132
/**

lib/private/Files/SetupManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,13 @@ public function setupRoot(): void {
337337
if ($this->rootSetup) {
338338
return;
339339
}
340+
341+
$this->setupBuiltinWrappers();
342+
340343
$this->rootSetup = true;
341344

342345
$this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
343346

344-
$this->setupBuiltinWrappers();
345-
346347
$rootMounts = $this->mountProviderCollection->getRootMounts();
347348
foreach ($rootMounts as $rootMountProvider) {
348349
$this->mountManager->addMount($rootMountProvider);

0 commit comments

Comments
 (0)