mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
move teardown logic to SetupManager
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
15ff65c12f
commit
5c0fe93498
10 changed files with 90 additions and 55 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -222,4 +222,10 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
|
|||
}, []);
|
||||
return $mounts;
|
||||
}
|
||||
|
||||
public function clearProviders() {
|
||||
$this->providers = [];
|
||||
$this->homeProviders = [];
|
||||
$this->rootProviders = [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -492,16 +500,6 @@ class Filesystem {
|
|||
return self::$defaultInstance->getRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue