Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-02-23 20:11:46 +0300
committerRobin Appelman <robin@icewind.nl>2022-03-04 18:29:50 +0300
commit5c0fe934988960ece3ac71d5a1dfc8df405413aa (patch)
treea4b4cded5a1876ba58651f87a385df16c2460f63 /lib
parent15ff65c12fafbe1c4026fa6f734fb58fdbdcda11 (diff)
move teardown logic to SetupManager
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/Files/Config/MountProviderCollection.php6
-rw-r--r--lib/private/Files/Filesystem.php22
-rw-r--r--lib/private/Files/Mount/Manager.php14
-rw-r--r--lib/private/Files/Node/Root.php50
-rw-r--r--lib/private/Files/SetupManager.php26
-rw-r--r--lib/private/Files/View.php7
-rw-r--r--lib/private/Server.php8
-rw-r--r--lib/private/legacy/OC_Util.php8
10 files changed, 90 insertions, 55 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 6fd3d9207db..59f4c11843c 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -271,6 +271,7 @@ return array(
'OCP\\Files\\Events\\Node\\BeforeNodeRenamedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeRenamedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeTouchedEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeTouchedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent' => $baseDir . '/lib/public/Files/Events/Node/BeforeNodeWrittenEvent.php',
+ 'OCP\\Files\\Events\\Node\\FilesystemTearedDownEvent' => $baseDir . '/lib/public/Files/Events/Node/FilesystemTearedDownEvent.php',
'OCP\\Files\\Events\\Node\\NodeCopiedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeCopiedEvent.php',
'OCP\\Files\\Events\\Node\\NodeCreatedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeCreatedEvent.php',
'OCP\\Files\\Events\\Node\\NodeDeletedEvent' => $baseDir . '/lib/public/Files/Events/Node/NodeDeletedEvent.php',
@@ -1162,6 +1163,7 @@ return array(
'OC\\Files\\Search\\SearchComparison' => $baseDir . '/lib/private/Files/Search/SearchComparison.php',
'OC\\Files\\Search\\SearchOrder' => $baseDir . '/lib/private/Files/Search/SearchOrder.php',
'OC\\Files\\Search\\SearchQuery' => $baseDir . '/lib/private/Files/Search/SearchQuery.php',
+ 'OC\\Files\\SetupManager' => $baseDir . '/lib/private/Files/SetupManager.php',
'OC\\Files\\SimpleFS\\NewSimpleFile' => $baseDir . '/lib/private/Files/SimpleFS/NewSimpleFile.php',
'OC\\Files\\SimpleFS\\SimpleFile' => $baseDir . '/lib/private/Files/SimpleFS/SimpleFile.php',
'OC\\Files\\SimpleFS\\SimpleFolder' => $baseDir . '/lib/private/Files/SimpleFS/SimpleFolder.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index c8c0e7df381..2437fb0a9aa 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -300,6 +300,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Files\\Events\\Node\\BeforeNodeRenamedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeRenamedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeTouchedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeTouchedEvent.php',
'OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/BeforeNodeWrittenEvent.php',
+ 'OCP\\Files\\Events\\Node\\FilesystemTearedDownEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/FilesystemTearedDownEvent.php',
'OCP\\Files\\Events\\Node\\NodeCopiedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeCopiedEvent.php',
'OCP\\Files\\Events\\Node\\NodeCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeCreatedEvent.php',
'OCP\\Files\\Events\\Node\\NodeDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/NodeDeletedEvent.php',
@@ -1191,6 +1192,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Files\\Search\\SearchComparison' => __DIR__ . '/../../..' . '/lib/private/Files/Search/SearchComparison.php',
'OC\\Files\\Search\\SearchOrder' => __DIR__ . '/../../..' . '/lib/private/Files/Search/SearchOrder.php',
'OC\\Files\\Search\\SearchQuery' => __DIR__ . '/../../..' . '/lib/private/Files/Search/SearchQuery.php',
+ 'OC\\Files\\SetupManager' => __DIR__ . '/../../..' . '/lib/private/Files/SetupManager.php',
'OC\\Files\\SimpleFS\\NewSimpleFile' => __DIR__ . '/../../..' . '/lib/private/Files/SimpleFS/NewSimpleFile.php',
'OC\\Files\\SimpleFS\\SimpleFile' => __DIR__ . '/../../..' . '/lib/private/Files/SimpleFS/SimpleFile.php',
'OC\\Files\\SimpleFS\\SimpleFolder' => __DIR__ . '/../../..' . '/lib/private/Files/SimpleFS/SimpleFolder.php',
diff --git a/lib/private/Files/Config/MountProviderCollection.php b/lib/private/Files/Config/MountProviderCollection.php
index ba70e29ab8d..2ca53d385cf 100644
--- a/lib/private/Files/Config/MountProviderCollection.php
+++ b/lib/private/Files/Config/MountProviderCollection.php
@@ -222,4 +222,10 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
}, []);
return $mounts;
}
+
+ public function clearProviders() {
+ $this->providers = [];
+ $this->homeProviders = [];
+ $this->rootProviders = [];
+ }
}
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php
index e439b746bf6..0c444d5cd34 100644
--- a/lib/private/Files/Filesystem.php
+++ b/lib/private/Files/Filesystem.php
@@ -41,7 +41,9 @@ use OC\Cache\CappedMemoryCache;
use OC\Files\Config\MountProviderCollection;
use OC\Files\Mount\MountPoint;
use OC\Lockdown\Filesystem\NullStorage;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Events\Node\FilesystemTearedDownEvent;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\ILogger;
@@ -332,6 +334,13 @@ class Filesystem {
}
self::getLoader();
self::$defaultInstance = new View($root);
+ /** @var IEventDispatcher $eventDispatcher */
+ $eventDispatcher = \OC::$server->get(IEventDispatcher::class);
+ $eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () {
+ self::$defaultInstance = null;
+ self::$usersSetup = [];
+ self::$loaded = false;
+ });
if (!self::$mounts) {
self::$mounts = \OC::$server->getMountManager();
@@ -474,8 +483,7 @@ class Filesystem {
* tear down the filesystem, removing all storage providers
*/
public static function tearDown() {
- self::clearMounts();
- self::$defaultInstance = null;
+ \OC_Util::tearDownFS();
}
/**
@@ -493,16 +501,6 @@ class Filesystem {
}
/**
- * clear all mounts and storage backends
- */
- public static function clearMounts() {
- if (self::$mounts) {
- self::$usersSetup = [];
- self::$mounts->clear();
- }
- }
-
- /**
* mount an \OC\Files\Storage\Storage in our virtual filesystem
*
* @param \OC\Files\Storage\Storage|string $class
diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php
index 91b6ad36c87..7770b9a6c58 100644
--- a/lib/private/Files/Mount/Manager.php
+++ b/lib/private/Files/Mount/Manager.php
@@ -31,10 +31,13 @@ namespace OC\Files\Mount;
use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
use OC\Files\SetupManager;
+use OC\Setup;
use OCP\Diagnostics\IEventLogger;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
+use OCP\Files\NotFoundException;
use OCP\IUserSession;
class Manager implements IMountManager {
@@ -47,11 +50,12 @@ class Manager implements IMountManager {
public function __construct(
IEventLogger $eventLogger,
IMountProviderCollection $mountProviderCollection,
- IUserSession $userSession
+ IUserSession $userSession,
+ IEventDispatcher $eventDispatcher
) {
$this->pathCache = new CappedMemoryCache();
$this->inPathCache = new CappedMemoryCache();
- $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userSession);
+ $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userSession, $eventDispatcher);
}
/**
@@ -122,7 +126,7 @@ class Manager implements IMountManager {
}
if ($current === '') {
- return null;
+ throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
}
$current = dirname($current);
@@ -214,4 +218,8 @@ class Manager implements IMountManager {
}
return $path;
}
+
+ public function getSetupManager(): SetupManager {
+ return $this->setupManager;
+ }
}
diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php
index b5707c87543..6f47b49c66a 100644
--- a/lib/private/Files/Node/Root.php
+++ b/lib/private/Files/Node/Root.php
@@ -35,13 +35,17 @@ namespace OC\Files\Node;
use OC\Cache\CappedMemoryCache;
use OC\Files\Mount\Manager;
use OC\Files\Mount\MountPoint;
+use OC\Files\View;
use OC\Hooks\PublicEmitter;
use OC\User\NoUserException;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IUserMountCache;
+use OCP\Files\Events\Node\FilesystemTearedDownEvent;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\ILogger;
+use OCP\IUser;
use OCP\IUserManager;
/**
@@ -64,35 +68,32 @@ use OCP\IUserManager;
* @package OC\Files\Node
*/
class Root extends Folder implements IRootFolder {
- /** @var Manager */
- private $mountManager;
- /** @var PublicEmitter */
- private $emitter;
- /** @var null|\OC\User\User */
- private $user;
- /** @var CappedMemoryCache */
- private $userFolderCache;
- /** @var IUserMountCache */
- private $userMountCache;
- /** @var ILogger */
- private $logger;
- /** @var IUserManager */
- private $userManager;
+ private Manager $mountManager;
+ private PublicEmitter $emitter;
+ private ?IUser $user;
+ private CappedMemoryCache $userFolderCache;
+ private IUserMountCache $userMountCache;
+ private ILogger $logger;
+ private IUserManager $userManager;
+ private IEventDispatcher $eventDispatcher;
/**
- * @param \OC\Files\Mount\Manager $manager
- * @param \OC\Files\View $view
- * @param \OC\User\User|null $user
+ * @param Manager $manager
+ * @param View $view
+ * @param IUser|null $user
* @param IUserMountCache $userMountCache
* @param ILogger $logger
* @param IUserManager $userManager
*/
- public function __construct($manager,
+ public function __construct(
+ $manager,
$view,
$user,
- IUserMountCache $userMountCache,
- ILogger $logger,
- IUserManager $userManager) {
+ IUserMountCache $userMountCache,
+ ILogger $logger,
+ IUserManager $userManager,
+ IEventDispatcher $eventDispatcher
+ ) {
parent::__construct($this, $view, '');
$this->mountManager = $manager;
$this->user = $user;
@@ -101,6 +102,9 @@ class Root extends Folder implements IRootFolder {
$this->userMountCache = $userMountCache;
$this->logger = $logger;
$this->userManager = $userManager;
+ $eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () {
+ $this->userFolderCache = new CappedMemoryCache();
+ });
}
/**
@@ -393,10 +397,6 @@ class Root extends Folder implements IRootFolder {
return $this->userFolderCache->get($userId);
}
- public function clearCache() {
- $this->userFolderCache = new CappedMemoryCache();
- }
-
public function getUserMountCache() {
return $this->userMountCache;
}
diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php
index 56f321666b3..20be8178676 100644
--- a/lib/private/Files/SetupManager.php
+++ b/lib/private/Files/SetupManager.php
@@ -23,7 +23,9 @@ declare(strict_types=1);
namespace OC\Files;
+use OC\Files\ObjectStore\HomeObjectStoreStorage;
use OC\Files\Storage\Common;
+use OC\Files\Storage\Home;
use OC\Files\Storage\Storage;
use OC\Files\Storage\Wrapper\Availability;
use OC\Files\Storage\Wrapper\Encoding;
@@ -34,8 +36,9 @@ use OC_Hook;
use OC_Util;
use OCP\Constants;
use OCP\Diagnostics\IEventLogger;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
-use OCP\Files\IHomeStorage;
+use OCP\Files\Events\Node\FilesystemTearedDownEvent;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
@@ -49,17 +52,20 @@ class SetupManager {
private IMountManager $mountManager;
private IUserSession $userSession;
private array $setupUsers = [];
+ private IEventDispatcher $eventDispatcher;
public function __construct(
IEventLogger $eventLogger,
IMountProviderCollection $mountProviderCollection,
IMountManager $mountManager,
- IUserSession $userSession
+ IUserSession $userSession,
+ IEventDispatcher $eventDispatcher
) {
$this->eventLogger = $eventLogger;
$this->mountProviderCollection = $mountProviderCollection;
$this->mountManager = $mountManager;
$this->userSession = $userSession;
+ $this->eventDispatcher = $eventDispatcher;
}
private function setupBuiltinWrappers() {
@@ -102,7 +108,7 @@ class SetupManager {
/**
* @var Storage $storage
*/
- if ($storage->instanceOfStorage(IHomeStorage::class)) {
+ if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
if (is_object($storage->getUser())) {
$quota = OC_Util::getUserQuota($storage->getUser());
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
@@ -171,24 +177,30 @@ class SetupManager {
if ($this->rootSetup) {
return;
}
+ $this->rootSetup = true;
$this->eventLogger->start('setup_root_fs', 'Setup root filesystem');
// load all filesystem apps before, so no setup-hook gets lost
OC_App::loadApps(['filesystem']);
-
- $this->rootSetup = true;
$prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
$this->setupBuiltinWrappers();
Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
- $rootMountProviders = $this->mountProviderCollection->getRootMounts();
- foreach ($rootMountProviders as $rootMountProvider) {
+ $rootMounts = $this->mountProviderCollection->getRootMounts();
+ foreach ($rootMounts as $rootMountProvider) {
$this->mountManager->addMount($rootMountProvider);
}
$this->eventLogger->end('setup_root_fs');
}
+
+ public function tearDown() {
+ $this->setupUsers = [];
+ $this->rootSetup = false;
+ $this->mountManager->clear();
+ $this->eventDispatcher->dispatchTyped(new FilesystemTearedDownEvent());
+ }
}
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 3cdc6166840..6f96f911785 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1739,12 +1739,13 @@ class View {
$manager = Filesystem::getMountManager();
$mounts = $manager->findIn($this->fakeRoot);
$mounts[] = $manager->find($this->fakeRoot);
- // reverse the array so we start with the storage this view is in
+ $mounts = array_filter($mounts);
+ // reverse the array, so we start with the storage this view is in
// which is the most likely to contain the file we're looking for
$mounts = array_reverse($mounts);
- // put non shared mounts in front of the shared mount
- // this prevent unneeded recursion into shares
+ // put non-shared mounts in front of the shared mount
+ // this prevents unneeded recursion into shares
usort($mounts, function (IMountPoint $a, IMountPoint $b) {
return $a instanceof SharedMount && (!$b instanceof SharedMount) ? 1 : -1;
});
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 8d1f377251c..6101c9a0a61 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -95,6 +95,7 @@ use OC\Files\Mount\RootMountProvider;
use OC\Files\Node\HookConnector;
use OC\Files\Node\LazyRoot;
use OC\Files\Node\Root;
+use OC\Files\SetupManager;
use OC\Files\Storage\StorageFactory;
use OC\Files\Template\TemplateManager;
use OC\Files\Type\Loader;
@@ -423,7 +424,8 @@ class Server extends ServerContainer implements IServerContainer {
null,
$c->get(IUserMountCache::class),
$this->get(ILogger::class),
- $this->get(IUserManager::class)
+ $this->get(IUserManager::class),
+ $this->get(IEventDispatcher::class),
);
$previewConnector = new \OC\Preview\WatcherConnector(
@@ -1091,6 +1093,10 @@ class Server extends ServerContainer implements IServerContainer {
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
+ $this->registerService(SetupManager::class, function ($c) {
+ // create the setupmanager through the mount manager to resolve the cyclic dependency
+ return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
+ });
$this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('MountManager', IMountManager::class);
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 1d224ed460d..ceed79bc9d5 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -112,6 +112,7 @@ class OC_Util {
} else {
$setupManager->setupRoot();
}
+ return true;
}
/**
@@ -264,10 +265,9 @@ class OC_Util {
* @suppress PhanUndeclaredMethod
*/
public static function tearDownFS() {
- \OC\Files\Filesystem::tearDown();
- \OC::$server->getRootFolder()->clearCache();
- self::$fsSetup = false;
- self::$rootFsSetup = false;
+ /** @var SetupManager $setupManager */
+ $setupManager = \OC::$server->get(SetupManager::class);
+ $setupManager->tearDown();
}
/**