From 841a6a084ec5b52fe2fad6638dc548695da24881 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 16 Nov 2022 17:47:52 +0100 Subject: [PATCH] delay updating setup providers untill we register the mounts otherwise the fallback to a full setup for a missing cached mount provider will lead to a race condition Signed-off-by: Robin Appelman --- lib/private/Files/SetupManager.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index d52a291cd99c0..ec5cd59d96011 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -40,6 +40,7 @@ use OCP\Constants; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\IHomeMountProvider; use OCP\Files\Config\IMountProvider; use OCP\Files\Config\IUserMountCache; @@ -414,9 +415,9 @@ public function setupForPath(string $path, bool $includeChildren = false): void $mounts = []; if (!in_array($cachedMount->getMountProvider(), $setupProviders)) { - $setupProviders[] = $cachedMount->getMountProvider(); $currentProviders[] = $cachedMount->getMountProvider(); if ($cachedMount->getMountProvider()) { + $setupProviders[] = $cachedMount->getMountProvider(); $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]); } else { $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup"); @@ -427,16 +428,21 @@ public function setupForPath(string $path, bool $includeChildren = false): void if ($includeChildren) { $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path); - foreach ($subCachedMounts as $cachedMount) { - if (!in_array($cachedMount->getMountProvider(), $setupProviders)) { - $setupProviders[] = $cachedMount->getMountProvider(); - $currentProviders[] = $cachedMount->getMountProvider(); - if ($cachedMount->getMountProvider()) { + + $needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) { + return $needsFullSetup || $cachedMountInfo->getMountProvider() === ''; + }, false); + + if ($needsFullSetup) { + $this->logger->debug("mount has no provider set, performing full setup"); + $this->setupForUser($user); + return; + } else { + foreach ($subCachedMounts as $cachedMount) { + if (!in_array($cachedMount->getMountProvider(), $setupProviders)) { + $currentProviders[] = $cachedMount->getMountProvider(); + $setupProviders[] = $cachedMount->getMountProvider(); $mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()])); - } else { - $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup"); - $this->setupForUser($user); - return; } } }