From 7630d7a934c8e8036313824d95e5aa9de80dab96 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 10 Feb 2022 14:15:07 +0100 Subject: [PATCH 1/9] more type hints for ICachedMountInfo and IMountManager Signed-off-by: Robin Appelman --- .../Files/Config/CachedMountFileInfo.php | 3 +- lib/private/Files/Config/CachedMountInfo.php | 55 +++++-------------- .../Files/Config/LazyStorageMountInfo.php | 16 +++--- lib/private/Files/Mount/Manager.php | 12 ++-- .../Files/Config/ICachedMountFileInfo.php | 4 +- lib/public/Files/Config/ICachedMountInfo.php | 16 +++--- lib/public/Files/Mount/IMountManager.php | 14 ++--- 7 files changed, 46 insertions(+), 74 deletions(-) diff --git a/lib/private/Files/Config/CachedMountFileInfo.php b/lib/private/Files/Config/CachedMountFileInfo.php index 71a6ddb9ea99e..11a9a505808c4 100644 --- a/lib/private/Files/Config/CachedMountFileInfo.php +++ b/lib/private/Files/Config/CachedMountFileInfo.php @@ -27,8 +27,7 @@ use OCP\IUser; class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInfo { - /** @var string */ - private $internalPath; + private string $internalPath; public function __construct( IUser $user, diff --git a/lib/private/Files/Config/CachedMountInfo.php b/lib/private/Files/Config/CachedMountInfo.php index c70dba100a4b2..43c9fae63ece9 100644 --- a/lib/private/Files/Config/CachedMountInfo.php +++ b/lib/private/Files/Config/CachedMountInfo.php @@ -28,38 +28,13 @@ use OCP\IUser; class CachedMountInfo implements ICachedMountInfo { - /** - * @var IUser - */ - protected $user; - - /** - * @var int - */ - protected $storageId; - - /** - * @var int - */ - protected $rootId; - - /** - * @var string - */ - protected $mountPoint; - - /** - * @var int|null - */ - protected $mountId; - - /** - * @var string - */ - protected $rootInternalPath; - - /** @var string */ - protected $mountProvider; + protected IUser $user; + protected int $storageId; + protected int $rootId; + protected string $mountPoint; + protected ?int $mountId; + protected string $rootInternalPath; + protected string $mountProvider; /** * CachedMountInfo constructor. @@ -95,28 +70,28 @@ public function __construct( /** * @return IUser */ - public function getUser() { + public function getUser(): IUser { return $this->user; } /** * @return int the numeric storage id of the mount */ - public function getStorageId() { + public function getStorageId(): int { return $this->storageId; } /** * @return int the fileid of the root of the mount */ - public function getRootId() { + public function getRootId(): int { return $this->rootId; } /** - * @return Node the root node of the mount + * @return Node|null the root node of the mount */ - public function getMountPointNode() { + public function getMountPointNode(): ?Node { // TODO injection etc Filesystem::initMountPoints($this->getUser()->getUID()); $userNode = \OC::$server->getUserFolder($this->getUser()->getUID()); @@ -131,7 +106,7 @@ public function getMountPointNode() { /** * @return string the mount point of the mount for the user */ - public function getMountPoint() { + public function getMountPoint(): string { return $this->mountPoint; } @@ -141,7 +116,7 @@ public function getMountPoint() { * @return int|null mount id or null if not applicable * @since 9.1.0 */ - public function getMountId() { + public function getMountId(): ?int { return $this->mountId; } @@ -150,7 +125,7 @@ public function getMountId() { * * @return string */ - public function getRootInternalPath() { + public function getRootInternalPath(): string { return $this->rootInternalPath; } diff --git a/lib/private/Files/Config/LazyStorageMountInfo.php b/lib/private/Files/Config/LazyStorageMountInfo.php index fd3bbcbe0fbfd..78055a2cdb864 100644 --- a/lib/private/Files/Config/LazyStorageMountInfo.php +++ b/lib/private/Files/Config/LazyStorageMountInfo.php @@ -25,8 +25,7 @@ use OCP\IUser; class LazyStorageMountInfo extends CachedMountInfo { - /** @var IMountPoint */ - private $mount; + private IMountPoint $mount; /** * CachedMountInfo constructor. @@ -37,12 +36,15 @@ class LazyStorageMountInfo extends CachedMountInfo { public function __construct(IUser $user, IMountPoint $mount) { $this->user = $user; $this->mount = $mount; + $this->rootId = 0; + $this->storageId = 0; + $this->mountPoint = ''; } /** * @return int the numeric storage id of the mount */ - public function getStorageId() { + public function getStorageId(): int { if (!$this->storageId) { $this->storageId = $this->mount->getNumericStorageId(); } @@ -52,7 +54,7 @@ public function getStorageId() { /** * @return int the fileid of the root of the mount */ - public function getRootId() { + public function getRootId(): int { if (!$this->rootId) { $this->rootId = $this->mount->getStorageRootId(); } @@ -62,14 +64,14 @@ public function getRootId() { /** * @return string the mount point of the mount for the user */ - public function getMountPoint() { + public function getMountPoint(): string { if (!$this->mountPoint) { $this->mountPoint = $this->mount->getMountPoint(); } return parent::getMountPoint(); } - public function getMountId() { + public function getMountId(): ?int { return $this->mount->getMountId(); } @@ -78,7 +80,7 @@ public function getMountId() { * * @return string */ - public function getRootInternalPath() { + public function getRootInternalPath(): string { return $this->mount->getInternalPath($this->mount->getMountPoint()); } diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 22b05b1f3844c..cfb008a94d1e7 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -35,13 +35,9 @@ class Manager implements IMountManager { /** @var MountPoint[] */ - private $mounts = []; - - /** @var CappedMemoryCache */ - private $pathCache; - - /** @var CappedMemoryCache */ - private $inPathCache; + private array $mounts = []; + private CappedMemoryCache $pathCache; + private CappedMemoryCache $inPathCache; public function __construct() { $this->pathCache = new CappedMemoryCache(); @@ -99,7 +95,7 @@ private function setupForFind(string $path) { * @param string $path * @return MountPoint|null */ - public function find(string $path) { + public function find(string $path): ?MountPoint { $this->setupForFind($path); $path = Filesystem::normalizePath($path); diff --git a/lib/public/Files/Config/ICachedMountFileInfo.php b/lib/public/Files/Config/ICachedMountFileInfo.php index 4de0a1218b4a9..e6aa2ec38c88f 100644 --- a/lib/public/Files/Config/ICachedMountFileInfo.php +++ b/lib/public/Files/Config/ICachedMountFileInfo.php @@ -34,11 +34,11 @@ interface ICachedMountFileInfo extends ICachedMountInfo { * @return string * @since 13.0.0 */ - public function getInternalPath(); + public function getInternalPath(): string; /** * @return string * @since 13.0.0 */ - public function getPath(); + public function getPath(): string; } diff --git a/lib/public/Files/Config/ICachedMountInfo.php b/lib/public/Files/Config/ICachedMountInfo.php index 812e79cdbc899..dafd2423fdc1d 100644 --- a/lib/public/Files/Config/ICachedMountInfo.php +++ b/lib/public/Files/Config/ICachedMountInfo.php @@ -35,31 +35,31 @@ interface ICachedMountInfo { * @return IUser * @since 9.0.0 */ - public function getUser(); + public function getUser(): IUser; /** * @return int the numeric storage id of the mount * @since 9.0.0 */ - public function getStorageId(); + public function getStorageId(): int; /** * @return int the fileid of the root of the mount * @since 9.0.0 */ - public function getRootId(); + public function getRootId(): int; /** - * @return Node the root node of the mount + * @return Node|null the root node of the mount * @since 9.0.0 */ - public function getMountPointNode(); + public function getMountPointNode(): ?Node; /** * @return string the mount point of the mount for the user * @since 9.0.0 */ - public function getMountPoint(); + public function getMountPoint(): string; /** * Get the id of the configured mount @@ -67,7 +67,7 @@ public function getMountPoint(); * @return int|null mount id or null if not applicable * @since 9.1.0 */ - public function getMountId(); + public function getMountId(): ?int; /** * Get the internal path (within the storage) of the root of the mount @@ -75,7 +75,7 @@ public function getMountId(); * @return string * @since 11.0.0 */ - public function getRootInternalPath(); + public function getRootInternalPath(): string; /** * Get the class of the mount provider that this mount originates from diff --git a/lib/public/Files/Mount/IMountManager.php b/lib/public/Files/Mount/IMountManager.php index 1e8c674f8f507..eb8adc3223a53 100644 --- a/lib/public/Files/Mount/IMountManager.php +++ b/lib/public/Files/Mount/IMountManager.php @@ -37,7 +37,7 @@ interface IMountManager { /** * Add a new mount * - * @param \OCP\Files\Mount\IMountPoint $mount + * @param IMountPoint $mount * @since 8.2.0 */ public function addMount(IMountPoint $mount); @@ -63,16 +63,16 @@ public function moveMount(string $mountPoint, string $target); * Find the mount for $path * * @param string $path - * @return \OCP\Files\Mount\IMountPoint|null + * @return IMountPoint|null * @since 8.2.0 */ - public function find(string $path); + public function find(string $path): ?IMountPoint; /** * Find all mounts in $path * * @param string $path - * @return \OCP\Files\Mount\IMountPoint[] + * @return IMountPoint[] * @since 8.2.0 */ public function findIn(string $path): array; @@ -88,13 +88,13 @@ public function clear(); * Find mounts by storage id * * @param string $id - * @return \OCP\Files\Mount\IMountPoint[] + * @return IMountPoint[] * @since 8.2.0 */ public function findByStorageId(string $id): array; /** - * @return \OCP\Files\Mount\IMountPoint[] + * @return IMountPoint[] * @since 8.2.0 */ public function getAll(): array; @@ -103,7 +103,7 @@ public function getAll(): array; * Find mounts by numeric storage id * * @param int $id - * @return \OCP\Files\Mount\IMountPoint[] + * @return IMountPoint[] * @since 8.2.0 */ public function findByNumericId(int $id): array; From 15ff65c12fafbe1c4026fa6f734fb58fdbdcda11 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 10 Feb 2022 17:36:46 +0100 Subject: [PATCH 2/9] start moving filesystem setup logic to it's own place Signed-off-by: Robin Appelman --- lib/private/Files/Mount/Manager.php | 18 ++- lib/private/Files/SetupManager.php | 194 ++++++++++++++++++++++++++++ lib/private/legacy/OC_Util.php | 144 +-------------------- 3 files changed, 215 insertions(+), 141 deletions(-) create mode 100644 lib/private/Files/SetupManager.php diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index cfb008a94d1e7..91b6ad36c8744 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -30,18 +30,28 @@ use OC\Cache\CappedMemoryCache; use OC\Files\Filesystem; +use OC\Files\SetupManager; +use OCP\Diagnostics\IEventLogger; +use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; +use OCP\IUserSession; class Manager implements IMountManager { /** @var MountPoint[] */ private array $mounts = []; private CappedMemoryCache $pathCache; private CappedMemoryCache $inPathCache; + private SetupManager $setupManager; - public function __construct() { + public function __construct( + IEventLogger $eventLogger, + IMountProviderCollection $mountProviderCollection, + IUserSession $userSession + ) { $this->pathCache = new CappedMemoryCache(); $this->inPathCache = new CappedMemoryCache(); + $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userSession); } /** @@ -80,12 +90,12 @@ public function moveMount(string $mountPoint, string $target) { private function setupForFind(string $path) { if (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0) { // for appdata, we only setup the root bits, not the user bits - \OC_Util::setupRootFS(); + $this->setupManager->setupRoot(); } elseif (strpos($path, '/files_external/uploads/') === 0) { // for OC\Security\CertificateManager, we only setup the root bits, not the user bits - \OC_Util::setupRootFS(); + $this->setupManager->setupRoot(); } else { - \OC_Util::setupFS(); + $this->setupManager->setupForCurrentUser(); } } diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php new file mode 100644 index 0000000000000..56f321666b3ce --- /dev/null +++ b/lib/private/Files/SetupManager.php @@ -0,0 +1,194 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OC\Files; + +use OC\Files\Storage\Common; +use OC\Files\Storage\Storage; +use OC\Files\Storage\Wrapper\Availability; +use OC\Files\Storage\Wrapper\Encoding; +use OC\Files\Storage\Wrapper\PermissionsMask; +use OC\Files\Storage\Wrapper\Quota; +use OC_App; +use OC_Hook; +use OC_Util; +use OCP\Constants; +use OCP\Diagnostics\IEventLogger; +use OCP\Files\Config\IMountProviderCollection; +use OCP\Files\IHomeStorage; +use OCP\Files\Mount\IMountManager; +use OCP\Files\Mount\IMountPoint; +use OCP\Files\Storage\IStorage; +use OCP\IUser; +use OCP\IUserSession; + +class SetupManager { + private bool $rootSetup = false; + private IEventLogger $eventLogger; + private IMountProviderCollection $mountProviderCollection; + private IMountManager $mountManager; + private IUserSession $userSession; + private array $setupUsers = []; + + public function __construct( + IEventLogger $eventLogger, + IMountProviderCollection $mountProviderCollection, + IMountManager $mountManager, + IUserSession $userSession + ) { + $this->eventLogger = $eventLogger; + $this->mountProviderCollection = $mountProviderCollection; + $this->mountManager = $mountManager; + $this->userSession = $userSession; + } + + private function setupBuiltinWrappers() { + Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) { + if ($storage->instanceOfStorage(Common::class)) { + $storage->setMountOptions($mount->getOptions()); + } + return $storage; + }); + + Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) { + if (!$mount->getOption('enable_sharing', true)) { + return new PermissionsMask([ + 'storage' => $storage, + 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, + ]); + } + return $storage; + }); + + // install storage availability wrapper, before most other wrappers + Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) { + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { + return new Availability(['storage' => $storage]); + } + return $storage; + }); + + Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) { + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { + return new Encoding(['storage' => $storage]); + } + return $storage; + }); + + Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { + // set up quota for home storages, even for other users + // which can happen when using sharing + + /** + * @var Storage $storage + */ + if ($storage->instanceOfStorage(IHomeStorage::class)) { + if (is_object($storage->getUser())) { + $quota = OC_Util::getUserQuota($storage->getUser()); + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { + return new Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); + } + } + } + + return $storage; + }); + + Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) { + /* + * Do not allow any operations that modify the storage + */ + if ($mount->getOption('readonly', false)) { + return new PermissionsMask([ + 'storage' => $storage, + 'mask' => Constants::PERMISSION_ALL & ~( + Constants::PERMISSION_UPDATE | + Constants::PERMISSION_CREATE | + Constants::PERMISSION_DELETE + ), + ]); + } + return $storage; + }); + } + + public function setupForCurrentUser() { + $user = $this->userSession->getUser(); + if ($user) { + $this->setupForUser($user); + } else { + $this->setupRoot(); + } + } + + public function setupForUser(IUser $user) { + $this->setupRoot(); + + if (in_array($user->getUID(), $this->setupUsers, true)) { + return; + } + $this->setupUsers[] = $user->getUID(); + + $this->eventLogger->start('setup_fs', 'Setup filesystem'); + + $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false); + + OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]); + + Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); + + $userDir = '/' . $user->getUID() . '/files'; + + Filesystem::init($user, $userDir); + + OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]); + + $this->eventLogger->end('setup_fs'); + } + + public function setupRoot() { + //setting up the filesystem twice can only lead to trouble + if ($this->rootSetup) { + return; + } + + $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) { + $this->mountManager->addMount($rootMountProvider); + } + + $this->eventLogger->end('setup_root_fs'); + } +} diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 40dcbb13b9395..1d224ed460d1e 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -66,6 +66,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\AppFramework\Http\Request; +use OC\Files\SetupManager; use OCP\Files\Template\ITemplateManager; use OCP\IConfig; use OCP\IGroupManager; @@ -78,8 +79,6 @@ class OC_Util { public static $scripts = []; public static $styles = []; public static $headers = []; - private static $rootFsSetup = false; - private static $fsSetup = false; /** @var array Local cache of version.php */ private static $versionCache = null; @@ -88,122 +87,6 @@ protected static function getAppManager() { return \OC::$server->getAppManager(); } - /** - * Can be set up - * - * @param string $user - * @return boolean - * @description configure the initial filesystem based on the configuration - * @suppress PhanDeprecatedFunction - * @suppress PhanAccessMethodInternal - */ - public static function setupRootFS(string $user = '') { - //setting up the filesystem twice can only lead to trouble - if (self::$rootFsSetup) { - return false; - } - - \OC::$server->getEventLogger()->start('setup_root_fs', 'Setup root filesystem'); - - // load all filesystem apps before, so no setup-hook gets lost - OC_App::loadApps(['filesystem']); - - self::$rootFsSetup = true; - - \OC\Files\Filesystem::initMountManager(); - - $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { - /** @var \OC\Files\Storage\Common $storage */ - $storage->setMountOptions($mount->getOptions()); - } - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { - if (!$mount->getOption('enable_sharing', true)) { - return new \OC\Files\Storage\Wrapper\PermissionsMask([ - 'storage' => $storage, - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE - ]); - } - return $storage; - }); - - // install storage availability wrapper, before most other wrappers - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); - } - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); - } - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { - // set up quota for home storages, even for other users - // which can happen when using sharing - - /** - * @var \OC\Files\Storage\Storage $storage - */ - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') - ) { - /** @var \OC\Files\Storage\Home $storage */ - if (is_object($storage->getUser())) { - $quota = OC_Util::getUserQuota($storage->getUser()); - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { - return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); - } - } - } - - return $storage; - }); - - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { - /* - * Do not allow any operations that modify the storage - */ - if ($mount->getOption('readonly', false)) { - return new \OC\Files\Storage\Wrapper\PermissionsMask([ - 'storage' => $storage, - 'mask' => \OCP\Constants::PERMISSION_ALL & ~( - \OCP\Constants::PERMISSION_UPDATE | - \OCP\Constants::PERMISSION_CREATE | - \OCP\Constants::PERMISSION_DELETE - ), - ]); - } - return $storage; - }); - - OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); - - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); - - /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ - $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); - $rootMountProviders = $mountProviderCollection->getRootMounts(); - - /** @var \OC\Files\Mount\Manager $mountManager */ - $mountManager = \OC\Files\Filesystem::getMountManager(); - foreach ($rootMountProviders as $rootMountProvider) { - $mountManager->addMount($rootMountProvider); - } - - \OC::$server->getEventLogger()->end('setup_root_fs'); - - return true; - } - /** * Setup the file system * @@ -214,14 +97,6 @@ public static function setupRootFS(string $user = '') { * @suppress PhanAccessMethodInternal */ public static function setupFS(?string $user = '') { - self::setupRootFS($user ?? ''); - - if (self::$fsSetup) { - return false; - } - - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); - // If we are not forced to load a specific user we load the one that is logged in if ($user === '') { $userObject = \OC::$server->get(\OCP\IUserSession::class)->getUser(); @@ -229,19 +104,14 @@ public static function setupFS(?string $user = '') { $userObject = \OC::$server->get(\OCP\IUserManager::class)->get($user); } - //if we aren't logged in, or the user doesn't exist, there is no use to set up the filesystem - if ($userObject) { - self::$fsSetup = true; + /** @var SetupManager $setupManager */ + $setupManager = \OC::$server->get(SetupManager::class); - $userDir = '/' . $userObject->getUID() . '/files'; - - //jail the user into his "home" directory - \OC\Files\Filesystem::init($userObject, $userDir); - - OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $userObject->getUID(), 'user_dir' => $userDir]); + if ($userObject) { + $setupManager->setupForUser($userObject); + } else { + $setupManager->setupRoot(); } - \OC::$server->getEventLogger()->end('setup_fs'); - return true; } /** From 5c0fe934988960ece3ac71d5a1dfc8df405413aa Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 23 Feb 2022 18:11:46 +0100 Subject: [PATCH 3/9] move teardown logic to SetupManager Signed-off-by: Robin Appelman --- lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + .../Files/Config/MountProviderCollection.php | 6 +++ lib/private/Files/Filesystem.php | 22 ++++---- lib/private/Files/Mount/Manager.php | 14 ++++-- lib/private/Files/Node/Root.php | 50 +++++++++---------- lib/private/Files/SetupManager.php | 26 +++++++--- lib/private/Files/View.php | 7 +-- lib/private/Server.php | 8 ++- lib/private/legacy/OC_Util.php | 8 +-- 10 files changed, 90 insertions(+), 55 deletions(-) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 6fd3d9207db39..59f4c11843ca7 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -271,6 +271,7 @@ '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 @@ '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 c8c0e7df381eb..2437fb0a9aa05 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 ba70e29ab8dca..2ca53d385cff5 100644 --- a/lib/private/Files/Config/MountProviderCollection.php +++ b/lib/private/Files/Config/MountProviderCollection.php @@ -222,4 +222,10 @@ public function getRootMounts(): array { }, []); 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 e439b746bf61e..0c444d5cd34dd 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -41,7 +41,9 @@ 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 @@ public static function init($user, $root) { } 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 @@ public static function getView() { * tear down the filesystem, removing all storage providers */ public static function tearDown() { - self::clearMounts(); - self::$defaultInstance = null; + \OC_Util::tearDownFS(); } /** @@ -492,16 +500,6 @@ public static function getRoot() { 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 * diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 91b6ad36c8744..7770b9a6c58d8 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -31,10 +31,13 @@ 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 @@ public function find(string $path): ?MountPoint { } 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 @@ private function formatPath(string $path): string { } 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 b5707c8754333..6f47b49c66a22 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -35,13 +35,17 @@ 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 @@ * @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 @@ public function __construct($manager, $this->userMountCache = $userMountCache; $this->logger = $logger; $this->userManager = $userManager; + $eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () { + $this->userFolderCache = new CappedMemoryCache(); + }); } /** @@ -393,10 +397,6 @@ public function getUserFolder($userId) { 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 56f321666b3ce..20be8178676ab 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -23,7 +23,9 @@ 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_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 @@ private function setupBuiltinWrappers() { /** * @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 @@ public function setupRoot() { 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 3cdc6166840ad..6f96f91178546 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1739,12 +1739,13 @@ public function getPath($id, int $storageId = null) { $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 8d1f377251c3d..6101c9a0a612f 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -95,6 +95,7 @@ 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 @@ public function __construct($webRoot, \OC\Config $config) { 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 @@ public function __construct($webRoot, \OC\Config $config) { /** @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 1d224ed460d1e..ceed79bc9d5a2 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -112,6 +112,7 @@ public static function setupFS(?string $user = '') { } else { $setupManager->setupRoot(); } + return true; } /** @@ -264,10 +265,9 @@ public static function copyr($source, \OCP\Files\Folder $target) { * @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(); } /** From 1c468129afa2b2ec4a370a879f8eaffd22768baf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 23 Feb 2022 18:29:08 +0100 Subject: [PATCH 4/9] adjust tests to new fs setup Signed-off-by: Robin Appelman --- .../unit/Connector/Sabre/ObjectTreeTest.php | 9 ++-- .../tests/PersonalMountTest.php | 11 ++++- apps/files_sharing/lib/External/Manager.php | 6 ++- .../tests/External/ManagerTest.php | 22 +++++++--- lib/composer/composer/autoload_classmap.php | 2 +- lib/composer/composer/autoload_static.php | 2 +- lib/private/Files/Filesystem.php | 4 +- lib/private/Files/Node/Root.php | 4 +- lib/private/Files/SetupManager.php | 4 +- .../Events/Node/FilesystemTornDownEvent.php | 32 ++++++++++++++ tests/lib/Cache/FileCacheTest.php | 19 +++----- tests/lib/Files/Cache/UpdaterLegacyTest.php | 6 ++- tests/lib/Files/Cache/UpdaterTest.php | 2 - tests/lib/Files/Config/UserMountCacheTest.php | 2 + tests/lib/Files/Mount/ManagerTest.php | 13 ++++-- tests/lib/Files/Node/FileTest.php | 25 ++++++----- tests/lib/Files/Node/FolderTest.php | 44 +++++++++---------- tests/lib/Files/Node/HookConnectorTest.php | 3 +- tests/lib/Files/Node/IntegrationTest.php | 15 +++++-- tests/lib/Files/Node/NodeTest.php | 14 ++++-- tests/lib/Files/Node/RootTest.php | 22 +++++++--- tests/lib/Files/PathVerificationTest.php | 2 +- tests/lib/Files/ViewTest.php | 16 +++++-- tests/lib/HelperStorageTest.php | 18 ++++---- tests/lib/SubAdminTest.php | 2 + tests/lib/TestCase.php | 23 ++++++++++ tests/lib/Traits/EncryptionTrait.php | 21 ++++++--- tests/lib/Traits/UserTrait.php | 18 +++++++- 28 files changed, 252 insertions(+), 109 deletions(-) create mode 100644 lib/public/Files/Events/Node/FilesystemTornDownEvent.php diff --git a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php index d77f65b33f5bb..7416cf7a3f7ae 100644 --- a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php @@ -34,6 +34,7 @@ use OC\Files\View; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\ObjectTree; +use OCP\Files\Mount\IMountManager; /** * Class ObjectTreeTest @@ -266,7 +267,7 @@ public function nodeForPathProvider() { ]; } - + public function testGetNodeForPathInvalidPath() { $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); @@ -287,8 +288,7 @@ public function testGetNodeForPathInvalidPath() { $rootNode = $this->getMockBuilder(Directory::class) ->disableOriginalConstructor() ->getMock(); - $mountManager = $this->getMockBuilder(Manager::class) - ->getMock(); + $mountManager = $this->createMock(IMountManager::class); $tree = new \OCA\DAV\Connector\Sabre\ObjectTree(); $tree->init($rootNode, $view, $mountManager); @@ -314,8 +314,7 @@ public function testGetNodeForPathRoot() { $rootNode = $this->getMockBuilder(Directory::class) ->disableOriginalConstructor() ->getMock(); - $mountManager = $this->getMockBuilder(Manager::class) - ->getMock(); + $mountManager = $this->createMock(IMountManager::class); $tree = new \OCA\DAV\Connector\Sabre\ObjectTree(); $tree->init($rootNode, $view, $mountManager); diff --git a/apps/files_external/tests/PersonalMountTest.php b/apps/files_external/tests/PersonalMountTest.php index b8a57657f9dee..fe0e4bc2533c3 100644 --- a/apps/files_external/tests/PersonalMountTest.php +++ b/apps/files_external/tests/PersonalMountTest.php @@ -27,6 +27,10 @@ use OC\Files\Mount\Manager; use OCA\Files_External\Lib\PersonalMount; use OCA\Files_External\Lib\StorageConfig; +use OCP\Diagnostics\IEventLogger; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\IMountProviderCollection; +use OCP\IUserSession; use Test\TestCase; class PersonalMountTest extends TestCase { @@ -47,7 +51,12 @@ public function testFindByStorageId() { $mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo'); - $mountManager = new Manager(); + $mountManager = new Manager( + $this->createMock(IEventLogger::class), + $this->createMock(IMountProviderCollection::class), + $this->createMock(IUserSession::class), + $this->createMock(IEventDispatcher::class) + ); $mountManager->addMount($mount); $this->assertEquals([$mount], $mountManager->findByStorageId('dummy')); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index a48e2a63ae451..a8510321a5a91 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -43,6 +43,7 @@ use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Files; +use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorageFactory; use OCP\Http\Client\IClientService; use OCP\IDBConnection; @@ -599,8 +600,9 @@ public function setMountPoint($source, $target) { } public function removeShare($mountPoint): bool { - $mountPointObj = $this->mountManager->find($mountPoint); - if ($mountPointObj === null) { + try { + $mountPointObj = $this->mountManager->find($mountPoint); + } catch (NotFoundException $e) { $this->logger->error('Mount point to remove share not found', ['mountPoint' => $mountPoint]); return false; } diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index ab7c682c3a668..30c96ebad6aaa 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -31,14 +31,18 @@ namespace OCA\Files_Sharing\Tests\External; use OC\Federation\CloudIdManager; +use OC\Files\SetupManager; use OC\Files\Storage\StorageFactory; use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\External\MountProvider; use OCA\Files_Sharing\Tests\TestCase; use OCP\Contacts\IManager; +use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; +use OCP\Files\Config\IMountProviderCollection; +use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IGroup; @@ -102,9 +106,13 @@ protected function setUp(): void { parent::setUp(); $this->uid = $this->getUniqueID('user'); - $this->createUser($this->uid, ''); - $this->user = \OC::$server->getUserManager()->get($this->uid); - $this->mountManager = new \OC\Files\Mount\Manager(); + $this->user = $this->createUser($this->uid, ''); + $this->mountManager = new \OC\Files\Mount\Manager( + $this->createMock(IEventLogger::class), + $this->createMock(IMountProviderCollection::class), + $this->createMock(IUserSession::class), + $this->createMock(IEventDispatcher::class) + ); $this->clientService = $this->getMockBuilder(IClientService::class) ->disableOriginalConstructor()->getMock(); $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); @@ -740,12 +748,12 @@ private function assertMount($mountPoint) { private function assertNotMount($mountPoint) { $mountPoint = rtrim($mountPoint, '/'); - $mount = $this->mountManager->find($this->getFullPath($mountPoint)); - if ($mount) { + try { + $mount = $this->mountManager->find($this->getFullPath($mountPoint)); $this->assertInstanceOf('\OCP\Files\Mount\IMountPoint', $mount); $this->assertNotEquals($this->getFullPath($mountPoint), rtrim($mount->getMountPoint(), '/')); - } else { - $this->assertNull($mount); + } catch (NotFoundException $e) { + } } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 59f4c11843ca7..6af6559af1188 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -271,7 +271,7 @@ '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\\FilesystemTornDownEvent' => $baseDir . '/lib/public/Files/Events/Node/FilesystemTornDownEvent.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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2437fb0a9aa05..69b00b4e2e789 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -300,7 +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\\FilesystemTornDownEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/Node/FilesystemTornDownEvent.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', diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 0c444d5cd34dd..71a6385bce166 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -43,7 +43,7 @@ use OC\Lockdown\Filesystem\NullStorage; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; -use OCP\Files\Events\Node\FilesystemTearedDownEvent; +use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorageFactory; use OCP\ILogger; @@ -336,7 +336,7 @@ public static function init($user, $root) { self::$defaultInstance = new View($root); /** @var IEventDispatcher $eventDispatcher */ $eventDispatcher = \OC::$server->get(IEventDispatcher::class); - $eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () { + $eventDispatcher->addListener(FilesystemTornDownEvent::class, function () { self::$defaultInstance = null; self::$usersSetup = []; self::$loaded = false; diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 6f47b49c66a22..4e4dc0ec0de8f 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -40,7 +40,7 @@ use OC\User\NoUserException; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; -use OCP\Files\Events\Node\FilesystemTearedDownEvent; +use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; @@ -102,7 +102,7 @@ public function __construct( $this->userMountCache = $userMountCache; $this->logger = $logger; $this->userManager = $userManager; - $eventDispatcher->addListener(FilesystemTearedDownEvent::class, function () { + $eventDispatcher->addListener(FilesystemTornDownEvent::class, function () { $this->userFolderCache = new CappedMemoryCache(); }); } diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 20be8178676ab..578372775ac17 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -38,7 +38,7 @@ use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProviderCollection; -use OCP\Files\Events\Node\FilesystemTearedDownEvent; +use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorage; @@ -201,6 +201,6 @@ public function tearDown() { $this->setupUsers = []; $this->rootSetup = false; $this->mountManager->clear(); - $this->eventDispatcher->dispatchTyped(new FilesystemTearedDownEvent()); + $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent()); } } diff --git a/lib/public/Files/Events/Node/FilesystemTornDownEvent.php b/lib/public/Files/Events/Node/FilesystemTornDownEvent.php new file mode 100644 index 0000000000000..d8e289a0a9f03 --- /dev/null +++ b/lib/public/Files/Events/Node/FilesystemTornDownEvent.php @@ -0,0 +1,32 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\Files\Events\Node; + +use OCP\EventDispatcher\Event; + +/** + * Event fired after the filesystem has been torn down + */ +class FilesystemTornDownEvent extends Event { +} diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php index a800fd005d9bc..41675b7c461c7 100644 --- a/tests/lib/Cache/FileCacheTest.php +++ b/tests/lib/Cache/FileCacheTest.php @@ -23,6 +23,7 @@ namespace Test\Cache; use OC\Files\Storage\Local; +use OCP\Files\Mount\IMountManager; use Test\Traits\UserTrait; /** @@ -68,15 +69,12 @@ protected function setUp(): void { //clear all proxies and hooks so we can do clean testing \OC_Hook::clear('OC_Filesystem'); - //set up temporary storage - $this->storage = \OC\Files\Filesystem::getStorage('/'); - \OC\Files\Filesystem::clearMounts(); + /** @var IMountManager $manager */ + $manager = \OC::$server->get(IMountManager::class); + $manager->removeMount('/test'); + $storage = new \OC\Files\Storage\Temporary([]); - \OC\Files\Filesystem::mount($storage, [], '/'); - $datadir = str_replace('local::', '', $storage->getId()); - $config = \OC::$server->getConfig(); - $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT.'/data/cache'); - $config->setSystemValue('cachedirectory', $datadir); + \OC\Files\Filesystem::mount($storage, [], '/test/cache'); //set up the users dir $this->rootView = new \OC\Files\View(''); @@ -94,17 +92,12 @@ protected function tearDown(): void { } \OC_User::setUserId($this->user); - \OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir); if ($this->instance) { $this->instance->clear(); $this->instance = null; } - // Restore the original mount point - \OC\Files\Filesystem::clearMounts(); - \OC\Files\Filesystem::mount($this->storage, [], '/'); - parent::tearDown(); } diff --git a/tests/lib/Files/Cache/UpdaterLegacyTest.php b/tests/lib/Files/Cache/UpdaterLegacyTest.php index 6d6cc08b3de1f..be0390db15e80 100644 --- a/tests/lib/Files/Cache/UpdaterLegacyTest.php +++ b/tests/lib/Files/Cache/UpdaterLegacyTest.php @@ -10,6 +10,7 @@ use OC\Files\Filesystem as Filesystem; use OC\Files\View; +use OCP\Files\Mount\IMountManager; /** * Class UpdaterLegacyTest @@ -61,7 +62,10 @@ protected function setUp(): void { Filesystem::init(self::$user, '/' . self::$user . '/files'); - Filesystem::clearMounts(); + /** @var IMountManager $manager */ + $manager = \OC::$server->get(IMountManager::class); + $manager->removeMount('/' . self::$user); + Filesystem::mount($this->storage, [], '/' . self::$user . '/files'); \OC_Hook::clear('OC_Filesystem'); diff --git a/tests/lib/Files/Cache/UpdaterTest.php b/tests/lib/Files/Cache/UpdaterTest.php index 4c99b24d9d6ce..7e0f686679335 100644 --- a/tests/lib/Files/Cache/UpdaterTest.php +++ b/tests/lib/Files/Cache/UpdaterTest.php @@ -50,8 +50,6 @@ protected function setUp(): void { } protected function tearDown(): void { - Filesystem::clearMounts(); - $this->logout(); parent::tearDown(); } diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 321ed2196fde5..0922dab36721a 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -45,6 +45,8 @@ class UserMountCacheTest extends TestCase { private $fileIds = []; protected function setUp(): void { + parent::setUp(); + $this->fileIds = []; $this->connection = \OC::$server->getDatabaseConnection(); $config = $this->getMockBuilder(IConfig::class) diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php index 1e80ec17ea118..3fd994edd56ba 100644 --- a/tests/lib/Files/Mount/ManagerTest.php +++ b/tests/lib/Files/Mount/ManagerTest.php @@ -9,6 +9,10 @@ namespace Test\Files\Mount; use OC\Files\Storage\Temporary; +use OCP\Diagnostics\IEventLogger; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\IMountProviderCollection; +use OCP\IUserSession; class LongId extends Temporary { public function getId() { @@ -24,12 +28,15 @@ class ManagerTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->manager = new \OC\Files\Mount\Manager(); + $this->manager = new \OC\Files\Mount\Manager( + $this->createMock(IEventLogger::class), + $this->createMock(IMountProviderCollection::class), + $this->createMock(IUserSession::class), + $this->createMock(IEventDispatcher::class), + ); } public function testFind() { - $this->assertNull($this->manager->find('/')); - $rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/'); $this->manager->addMount($rootMount); $this->assertEquals($rootMount, $this->manager->find('/')); diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index 6b5aaabbc28de..c381fd9b2beba 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -35,7 +35,7 @@ protected function getViewDeleteMethod() { public function testGetContent() { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $hook = function ($file) { @@ -65,7 +65,7 @@ public function testGetContentNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) @@ -84,7 +84,7 @@ public function testGetContentNotPermitted() { public function testPutContent() { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) @@ -111,7 +111,7 @@ public function testPutContentNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $this->view->expects($this->once()) @@ -126,7 +126,7 @@ public function testPutContentNotPermitted() { public function testGetMimeType() { /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $this->view->expects($this->once()) @@ -149,7 +149,8 @@ public function testFOpenRead() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $hook = function ($file) { @@ -184,7 +185,8 @@ public function testFOpenWrite() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $hooksCalled = 0; $hook = function ($file) use (&$hooksCalled) { @@ -223,7 +225,8 @@ public function testFOpenReadNotPermitted() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); @@ -248,7 +251,8 @@ public function testFOpenReadWriteNoReadPermissions() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); @@ -273,7 +277,8 @@ public function testFOpenReadWriteNoWritePermissions() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 72bd15d3922ac..d604786905d22 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -61,7 +61,7 @@ public function testGetDirectoryContent() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -93,7 +93,7 @@ public function testGet() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -113,7 +113,7 @@ public function testNodeExists() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -136,7 +136,7 @@ public function testNodeExistsNotExists() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -157,7 +157,7 @@ public function testNewFolder() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -187,7 +187,7 @@ public function testNewFolderNotPermitted() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -207,7 +207,7 @@ public function testNewFile() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -237,7 +237,7 @@ public function testNewFileNotPermitted() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -257,7 +257,7 @@ public function testGetFreeSpace() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -277,7 +277,7 @@ public function testSearch() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -321,7 +321,7 @@ public function testSearchInRoot() { $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -364,7 +364,7 @@ public function testSearchInStorageRoot() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->method('getUser') ->willReturn($this->user); @@ -407,7 +407,7 @@ public function testSearchSubStorages() { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -479,7 +479,7 @@ public function testGetById() { $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); @@ -530,7 +530,7 @@ public function testGetByIdMountRoot() { $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); @@ -577,7 +577,7 @@ public function testGetByIdOutsideFolder() { $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); @@ -627,7 +627,7 @@ public function testGetByIdMultipleStorages() { $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) ->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount1 = new MountPoint($storage, '/bar'); @@ -697,7 +697,7 @@ public function testGetUniqueName($name, $existingFiles, $expected) { $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $view->expects($this->any()) @@ -725,7 +725,7 @@ public function testRecent() { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */ $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) @@ -793,7 +793,7 @@ public function testRecentFolder() { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */ $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) @@ -860,7 +860,7 @@ public function testRecentJail() { /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */ $root = $this->getMockBuilder(Root::class) ->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) @@ -947,7 +947,7 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->getMock(); $root->expects($this->any()) ->method('getUser') diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 7990abad2314c..5e0b40172438c 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -78,7 +78,8 @@ protected function setUp(): void { \OC::$server->getUserManager()->get($this->userId), \OC::$server->getUserMountCache(), $this->createMock(ILogger::class), - $this->createMock(IUserManager::class) + $this->createMock(IUserManager::class), + $this->createMock(IEventDispatcher::class) ); $this->legacyDispatcher = \OC::$server->getEventDispatcher(); $this->eventDispatcher = \OC::$server->query(IEventDispatcher::class); diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php index 26cdf398d94a2..71e8793ad6f2c 100644 --- a/tests/lib/Files/Node/IntegrationTest.php +++ b/tests/lib/Files/Node/IntegrationTest.php @@ -11,9 +11,11 @@ use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\View; -use OC\User\User; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Mount\IMountManager; use OCP\ILogger; use OCP\IUserManager; +use Test\Traits\UserTrait; /** * Class IntegrationTest @@ -23,6 +25,8 @@ * @package Test\Files\Node */ class IntegrationTest extends \Test\TestCase { + use UserTrait; + /** * @var \OC\Files\Node\Root $root */ @@ -41,11 +45,12 @@ class IntegrationTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $manager = \OC\Files\Filesystem::getMountManager(); + /** @var IMountManager $manager */ + $manager = \OC::$server->get(IMountManager::class); \OC_Hook::clear('OC_Filesystem'); - $user = new User($this->getUniqueID('user'), new \Test\Util\User\Dummy, \OC::$server->getEventDispatcher()); + $user = $this->createUser($this->getUniqueID('user'), ''); $this->loginAsUser($user->getUID()); $this->view = new View(); @@ -55,7 +60,8 @@ protected function setUp(): void { $user, \OC::$server->getUserMountCache(), $this->createMock(ILogger::class), - $this->createMock(IUserManager::class) + $this->createMock(IUserManager::class), + $this->createMock(IEventDispatcher::class) ); $storage = new Temporary([]); $subStorage = new Temporary([]); @@ -63,6 +69,7 @@ protected function setUp(): void { $this->storages[] = $subStorage; $this->root->mount($storage, '/'); $this->root->mount($subStorage, '/substorage/'); + $manager->removeMount('/' . $user->getUID()); } protected function tearDown(): void { diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index 6ea5a6d7ffa5e..a60a20b99f3a0 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -11,6 +11,7 @@ use OC\Files\FileInfo; use OC\Files\Mount\Manager; use OC\Files\View; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -39,6 +40,8 @@ abstract class NodeTest extends \Test\TestCase { protected $logger; /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ protected $userManager; + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + protected $eventDispatcher; protected function setUp(): void { parent::setUp(); @@ -55,8 +58,9 @@ protected function setUp(): void { ->getMock(); $this->logger = $this->createMock(ILogger::class); $this->userManager = $this->createMock(IUserManager::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->eventDispatcher]) ->getMock(); } @@ -151,7 +155,8 @@ public function testDeleteHooks() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $root->listen('\OC\Files', 'preDelete', $preListener); @@ -409,7 +414,8 @@ public function testTouchHooks() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $root->listen('\OC\Files', 'preTouch', $preListener); $root->listen('\OC\Files', 'postTouch', $postListener); @@ -592,7 +598,7 @@ public function moveOrCopyProvider() { public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName) { /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) ->setMethods(['get']) ->getMock(); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index 13fdcb6590281..a7f7dc02e0176 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -13,6 +13,7 @@ use OC\Files\Mount\Manager; use OC\Files\Node\Folder; use OC\Files\View; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; @@ -33,6 +34,8 @@ class RootTest extends \Test\TestCase { private $logger; /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ private $userManager; + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + private $eventDispatcher; protected function setUp(): void { parent::setUp(); @@ -46,6 +49,7 @@ protected function setUp(): void { ->getMock(); $this->logger = $this->createMock(ILogger::class); $this->userManager = $this->createMock(IUserManager::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); } protected function getFileInfo($data) { @@ -71,7 +75,8 @@ public function testGet() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $view->expects($this->once()) @@ -107,7 +112,8 @@ public function testGetNotFound() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $view->expects($this->once()) @@ -135,7 +141,8 @@ public function testGetInvalidPath() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $root->get('/../foo'); @@ -157,7 +164,8 @@ public function testGetNoStorages() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $root->get('/bar/foo'); @@ -170,7 +178,8 @@ public function testGetUserFolder() { $this->user, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $user = $this->createMock(IUser::class); $user @@ -210,7 +219,8 @@ public function testGetUserFolderWithNoUserObj() { null, $this->userMountCache, $this->logger, - $this->userManager + $this->userManager, + $this->eventDispatcher ); $this->userManager ->expects($this->once()) diff --git a/tests/lib/Files/PathVerificationTest.php b/tests/lib/Files/PathVerificationTest.php index 18637daf9d739..3570acfaab413 100644 --- a/tests/lib/Files/PathVerificationTest.php +++ b/tests/lib/Files/PathVerificationTest.php @@ -30,7 +30,7 @@ protected function setUp(): void { $this->view = new View(); } - + public function testPathVerificationFileNameTooLong() { $this->expectException(\OCP\Files\InvalidPathException::class); $this->expectExceptionMessage('File name is too long'); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 15c9400864b08..7b735720ff13b 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -11,6 +11,7 @@ use OC\Files\Cache\Watcher; use OC\Files\Filesystem; use OC\Files\Mount\MountPoint; +use OC\Files\SetupManager; use OC\Files\Storage\Common; use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; @@ -19,6 +20,7 @@ use OCP\Files\Config\IMountProvider; use OCP\Files\FileInfo; use OCP\Files\GenericFileException; +use OCP\Files\Mount\IMountManager; use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; @@ -104,9 +106,10 @@ protected function setUp(): void { $this->groupObject->addUser($this->userObject); self::loginAsUser($this->user); - // clear mounts but somehow keep the root storage - // that was initialized above... - Filesystem::clearMounts(); + + /** @var IMountManager $manager */ + $manager = \OC::$server->get(IMountManager::class); + $manager->removeMount('/test'); $this->tempStorage = null; } @@ -125,6 +128,10 @@ protected function tearDown(): void { self::logout(); + /** @var SetupManager $setupManager */ + $setupManager = \OC::$server->get(SetupManager::class); + $setupManager->setupRoot(); + $this->userObject->delete(); $this->groupObject->delete(); @@ -224,12 +231,14 @@ public function testGetPath() { $storage1 = $this->getTestStorage(); $storage2 = $this->getTestStorage(); $storage3 = $this->getTestStorage(); + Filesystem::mount($storage1, [], '/'); Filesystem::mount($storage2, [], '/substorage'); Filesystem::mount($storage3, [], '/folder/anotherstorage'); $rootView = new View(''); + $cachedData = $rootView->getFileInfo('/foo.txt'); /** @var int $id1 */ $id1 = $cachedData['fileid']; @@ -316,7 +325,6 @@ public function testRemoveSharePermissionWhenSharingDisabledForUser($excludeGrou public function testCacheIncompleteFolder() { $storage1 = $this->getTestStorage(false); - Filesystem::clearMounts(); Filesystem::mount($storage1, [], '/incomplete'); $rootView = new View('/incomplete'); diff --git a/tests/lib/HelperStorageTest.php b/tests/lib/HelperStorageTest.php index 4166d60636699..6d7ea513d3f49 100644 --- a/tests/lib/HelperStorageTest.php +++ b/tests/lib/HelperStorageTest.php @@ -9,6 +9,8 @@ namespace Test; use OC\Files\Storage\Temporary; +use OCP\Files\Mount\IMountManager; +use Test\Traits\UserTrait; /** * Test the storage functions of OC_Helper @@ -16,6 +18,8 @@ * @group DB */ class HelperStorageTest extends \Test\TestCase { + use UserTrait; + /** @var string */ private $user; /** @var \OC\Files\Storage\Storage */ @@ -27,14 +31,15 @@ protected function setUp(): void { parent::setUp(); $this->user = $this->getUniqueID('user_'); - \OC_User::useBackend('dummy'); - \OC::$server->getUserManager()->createUser($this->user, $this->user); + $this->createUser($this->user, $this->user); - $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); - \OC\Files\Filesystem::clearMounts(); + + /** @var IMountManager $manager */ + $manager = \OC::$server->get(IMountManager::class); + $manager->removeMount('/' . $this->user); $this->storageMock = null; } @@ -47,13 +52,8 @@ protected function tearDown(): void { $this->storageMock = null; } \OC\Files\Filesystem::tearDown(); - \OC\Files\Filesystem::mount($this->storage, [], '/'); \OC_User::setUserId(''); - $user = \OC::$server->getUserManager()->get($this->user); - if ($user !== null) { - $user->delete(); - } \OC::$server->getConfig()->deleteAllUserValues($this->user); parent::tearDown(); diff --git a/tests/lib/SubAdminTest.php b/tests/lib/SubAdminTest.php index a3a795ce392bb..907abf4b7d8ac 100644 --- a/tests/lib/SubAdminTest.php +++ b/tests/lib/SubAdminTest.php @@ -49,6 +49,8 @@ class SubAdminTest extends \Test\TestCase { private $groups; protected function setUp(): void { + parent::setUp(); + $this->users = []; $this->groups = []; diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index b5dcd76faf90e..256fb95a85be1 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -25,14 +25,21 @@ use DOMDocument; use DOMNode; use OC\Command\QueueBus; +use OC\Files\Config\MountProviderCollection; use OC\Files\Filesystem; +use OC\Files\Mount\CacheMountProvider; +use OC\Files\Mount\LocalHomeMountProvider; +use OC\Files\Mount\RootMountProvider; +use OC\Files\SetupManager; use OC\Template\Base; use OCP\Command\IBus; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Defaults; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; abstract class TestCase extends \PHPUnit\Framework\TestCase { /** @var \OC\Command\QueueBus */ @@ -276,6 +283,22 @@ public static function tearDownAfterClass(): void { self::tearDownAfterClassCleanStrayHooks(); self::tearDownAfterClassCleanStrayLocks(); + /** @var SetupManager $setupManager */ + $setupManager = \OC::$server->get(SetupManager::class); + $setupManager->tearDown(); + + /** @var MountProviderCollection $mountProviderCollection */ + $mountProviderCollection = \OC::$server->get(MountProviderCollection::class); + $mountProviderCollection->clearProviders(); + + /** @var IConfig $config */ + $config = \OC::$server->get(IConfig::class); + $mountProviderCollection->registerProvider(new CacheMountProvider($config)); + $mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider()); + $mountProviderCollection->registerRootProvider(new RootMountProvider($config, \OC::$server->get(LoggerInterface::class))); + + $setupManager->setupRoot(); + parent::tearDownAfterClass(); } diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php index 6b74f7ca8eee3..9cb64c12d00b3 100644 --- a/tests/lib/Traits/EncryptionTrait.php +++ b/tests/lib/Traits/EncryptionTrait.php @@ -9,12 +9,13 @@ namespace Test\Traits; use OC\Encryption\EncryptionWrapper; -use OC\Files\Filesystem; +use OC\Files\SetupManager; use OC\Memcache\ArrayCache; use OCA\Encryption\AppInfo\Application; use OCA\Encryption\KeyManager; use OCA\Encryption\Users\Setup; use OCP\Encryption\IManager; +use OCP\IUserManager; /** * Enables encryption @@ -31,6 +32,11 @@ abstract protected static function assertTrue($condition, string $message = ''): private $originalEncryptionModule; + /** @var IUserManager */ + private $userManager; + /** @var SetupManager */ + private $setupManager; + /** * @var \OCP\IConfig */ @@ -47,18 +53,20 @@ protected function loginWithEncryption($user = '') { // needed for fully logout \OC::$server->getUserSession()->setUser(null); - Filesystem::tearDown(); + $this->setupManager->tearDown(); + \OC_User::setUserId($user); $this->postLogin(); \OC_Util::setupFS($user); - if (\OC::$server->getUserManager()->userExists($user)) { + if ($this->userManager->userExists($user)) { \OC::$server->getUserFolder($user); } } protected function setupForUser($name, $password) { - \OC_Util::tearDownFS(); - \OC_Util::setupFS($name); + $this->setupManager->tearDown(); + $this->setupManager->setupForUser($this->userManager->get($name)); + $container = $this->encryptionApp->getContainer(); /** @var KeyManager $keyManager */ $keyManager = $container->query(KeyManager::class); @@ -86,6 +94,9 @@ protected function setUpEncryptionTrait() { $this->markTestSkipped('Encryption not ready'); } + $this->userManager = \OC::$server->get(IUserManager::class); + $this->setupManager = \OC::$server->get(SetupManager::class); + \OC_App::loadApp('encryption'); $this->encryptionApp = new Application([], $isReady); diff --git a/tests/lib/Traits/UserTrait.php b/tests/lib/Traits/UserTrait.php index 229087a5200e5..3f7cfe419db45 100644 --- a/tests/lib/Traits/UserTrait.php +++ b/tests/lib/Traits/UserTrait.php @@ -8,6 +8,21 @@ namespace Test\Traits; +use OC\User\User; +use OCP\IUser; + +class DummyUser extends User { + private string $uid; + + public function __construct(string $uid) { + $this->uid = $uid; + } + + public function getUID(): string { + return $this->uid; + } +} + /** * Allow creating users in a temporary backend */ @@ -17,8 +32,9 @@ trait UserTrait { */ protected $userBackend; - protected function createUser($name, $password) { + protected function createUser($name, $password): IUser { $this->userBackend->createUser($name, $password); + return new DummyUser($name); } protected function setUpUserTrait() { From 22875bf367b69db4a76daed1a057407e7fbff2a6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 2 Mar 2022 17:11:06 +0100 Subject: [PATCH 5/9] move logic to decide what to setup to setupmanager Signed-off-by: Robin Appelman --- .../tests/PersonalMountTest.php | 4 +- .../tests/External/ManagerTest.php | 2 +- lib/private/Files/Mount/Manager.php | 27 +++-------- lib/private/Files/SetupManager.php | 48 +++++++++++++------ lib/public/Files/Mount/IMountManager.php | 2 +- tests/lib/Files/Mount/ManagerTest.php | 4 +- 6 files changed, 46 insertions(+), 41 deletions(-) diff --git a/apps/files_external/tests/PersonalMountTest.php b/apps/files_external/tests/PersonalMountTest.php index fe0e4bc2533c3..ff33f8e21a764 100644 --- a/apps/files_external/tests/PersonalMountTest.php +++ b/apps/files_external/tests/PersonalMountTest.php @@ -30,7 +30,7 @@ use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProviderCollection; -use OCP\IUserSession; +use OCP\IUserManager; use Test\TestCase; class PersonalMountTest extends TestCase { @@ -54,7 +54,7 @@ public function testFindByStorageId() { $mountManager = new Manager( $this->createMock(IEventLogger::class), $this->createMock(IMountProviderCollection::class), - $this->createMock(IUserSession::class), + $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class) ); $mountManager->addMount($mount); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 30c96ebad6aaa..b6e9593918c04 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -110,7 +110,7 @@ protected function setUp(): void { $this->mountManager = new \OC\Files\Mount\Manager( $this->createMock(IEventLogger::class), $this->createMock(IMountProviderCollection::class), - $this->createMock(IUserSession::class), + $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class) ); $this->clientService = $this->getMockBuilder(IClientService::class) diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 7770b9a6c58d8..b1506b2186422 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -31,14 +31,13 @@ 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; +use OCP\IUserManager; class Manager implements IMountManager { /** @var MountPoint[] */ @@ -50,12 +49,12 @@ class Manager implements IMountManager { public function __construct( IEventLogger $eventLogger, IMountProviderCollection $mountProviderCollection, - IUserSession $userSession, + IUserManager $userManager, IEventDispatcher $eventDispatcher ) { $this->pathCache = new CappedMemoryCache(); $this->inPathCache = new CappedMemoryCache(); - $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userSession, $eventDispatcher); + $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userManager, $eventDispatcher); } /** @@ -91,26 +90,14 @@ public function moveMount(string $mountPoint, string $target) { $this->inPathCache->clear(); } - private function setupForFind(string $path) { - if (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0) { - // for appdata, we only setup the root bits, not the user bits - $this->setupManager->setupRoot(); - } elseif (strpos($path, '/files_external/uploads/') === 0) { - // for OC\Security\CertificateManager, we only setup the root bits, not the user bits - $this->setupManager->setupRoot(); - } else { - $this->setupManager->setupForCurrentUser(); - } - } - /** * Find the mount for $path * * @param string $path - * @return MountPoint|null + * @return MountPoint */ - public function find(string $path): ?MountPoint { - $this->setupForFind($path); + public function find(string $path): MountPoint { + $this->setupManager->setupForPath($path); $path = Filesystem::normalizePath($path); if (isset($this->pathCache[$path])) { @@ -143,7 +130,7 @@ public function find(string $path): ?MountPoint { * @return MountPoint[] */ public function findIn(string $path): array { - $this->setupForFind($path); + $this->setupManager->setupForPath($path); $path = $this->formatPath($path); if (isset($this->inPathCache[$path])) { diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 578372775ac17..79622132208f0 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -43,14 +43,14 @@ use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorage; use OCP\IUser; -use OCP\IUserSession; +use OCP\IUserManager; class SetupManager { private bool $rootSetup = false; private IEventLogger $eventLogger; private IMountProviderCollection $mountProviderCollection; private IMountManager $mountManager; - private IUserSession $userSession; + private IUserManager $userManager; private array $setupUsers = []; private IEventDispatcher $eventDispatcher; @@ -58,13 +58,13 @@ public function __construct( IEventLogger $eventLogger, IMountProviderCollection $mountProviderCollection, IMountManager $mountManager, - IUserSession $userSession, + IUserManager $userManager, IEventDispatcher $eventDispatcher ) { $this->eventLogger = $eventLogger; $this->mountProviderCollection = $mountProviderCollection; $this->mountManager = $mountManager; - $this->userSession = $userSession; + $this->userManager = $userManager; $this->eventDispatcher = $eventDispatcher; } @@ -138,16 +138,10 @@ private function setupBuiltinWrappers() { }); } - public function setupForCurrentUser() { - $user = $this->userSession->getUser(); - if ($user) { - $this->setupForUser($user); - } else { - $this->setupRoot(); - } - } - - public function setupForUser(IUser $user) { + /** + * Setup the full filesystem for the specified user + */ + public function setupForUser(IUser $user): void { $this->setupRoot(); if (in_array($user->getUID(), $this->setupUsers, true)) { @@ -172,7 +166,10 @@ public function setupForUser(IUser $user) { $this->eventLogger->end('setup_fs'); } - public function setupRoot() { + /** + * Set up the root filesystem + */ + public function setupRoot(): void { //setting up the filesystem twice can only lead to trouble if ($this->rootSetup) { return; @@ -197,6 +194,27 @@ public function setupRoot() { $this->eventLogger->end('setup_root_fs'); } + /** + * Set up the filesystem for the specified path + */ + public function setupForPath(string $path): void { + if (substr_count($path, '/') < 2 || strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) { + $this->setupRoot(); + return; + } else { + [, $userId] = explode('/', $path); + } + + $user = $this->userManager->get($userId); + + if (!$user) { + $this->setupRoot(); + return; + } + + $this->setupForUser($user); + } + public function tearDown() { $this->setupUsers = []; $this->rootSetup = false; diff --git a/lib/public/Files/Mount/IMountManager.php b/lib/public/Files/Mount/IMountManager.php index eb8adc3223a53..aa760f53e961e 100644 --- a/lib/public/Files/Mount/IMountManager.php +++ b/lib/public/Files/Mount/IMountManager.php @@ -63,7 +63,7 @@ public function moveMount(string $mountPoint, string $target); * Find the mount for $path * * @param string $path - * @return IMountPoint|null + * @return IMountPoint * @since 8.2.0 */ public function find(string $path): ?IMountPoint; diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php index 3fd994edd56ba..159fffc7cb8b6 100644 --- a/tests/lib/Files/Mount/ManagerTest.php +++ b/tests/lib/Files/Mount/ManagerTest.php @@ -12,7 +12,7 @@ use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProviderCollection; -use OCP\IUserSession; +use OCP\IUserManager; class LongId extends Temporary { public function getId() { @@ -31,7 +31,7 @@ protected function setUp(): void { $this->manager = new \OC\Files\Mount\Manager( $this->createMock(IEventLogger::class), $this->createMock(IMountProviderCollection::class), - $this->createMock(IUserSession::class), + $this->createMock(IUserManager::class), $this->createMock(IEventDispatcher::class), ); } From 6c1d051ecd8bb4d76761da2c25d274e703a2fb97 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 2 Mar 2022 19:24:26 +0100 Subject: [PATCH 6/9] add template annotations to CappedMemoryCache Signed-off-by: Robin Appelman --- lib/private/Cache/CappedMemoryCache.php | 28 +++++++++++++++++++++---- lib/private/Files/Mount/Manager.php | 14 +++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/private/Cache/CappedMemoryCache.php b/lib/private/Cache/CappedMemoryCache.php index 584a53f0ff288..dd7cb32e90fa6 100644 --- a/lib/private/Cache/CappedMemoryCache.php +++ b/lib/private/Cache/CappedMemoryCache.php @@ -27,30 +27,42 @@ * In-memory cache with a capacity limit to keep memory usage in check * * Uses a simple FIFO expiry mechanism + * @template T */ class CappedMemoryCache implements ICache, \ArrayAccess { private $capacity; + /** @var T[] */ private $cache = []; public function __construct($capacity = 512) { $this->capacity = $capacity; } - public function hasKey($key) { + public function hasKey($key): bool { return isset($this->cache[$key]); } + /** + * @return ?T + */ public function get($key) { - return isset($this->cache[$key]) ? $this->cache[$key] : null; + return $this->cache[$key] ?? null; } - public function set($key, $value, $ttl = 0) { + /** + * @param string $key + * @param T$value + * @param int $ttl + * @return bool + */ + public function set($key, $value, $ttl = 0): bool { if (is_null($key)) { $this->cache[] = $value; } else { $this->cache[$key] = $value; } $this->garbageCollect(); + return true; } public function remove($key) { @@ -68,13 +80,18 @@ public function offsetExists($offset): bool { } /** - * @return mixed + * @return T */ #[\ReturnTypeWillChange] public function &offsetGet($offset) { return $this->cache[$offset]; } + /** + * @param string $key + * @param T$value + * @return void + */ public function offsetSet($offset, $value): void { $this->set($offset, $value); } @@ -83,6 +100,9 @@ public function offsetUnset($offset): void { $this->remove($offset); } + /** + * @return T[] + */ public function getData() { return $this->cache; } diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index b1506b2186422..fc78d71adb4eb 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -42,7 +42,9 @@ class Manager implements IMountManager { /** @var MountPoint[] */ private array $mounts = []; + /** @var CappedMemoryCache */ private CappedMemoryCache $pathCache; + /** @var CappedMemoryCache */ private CappedMemoryCache $inPathCache; private SetupManager $setupManager; @@ -94,9 +96,9 @@ public function moveMount(string $mountPoint, string $target) { * Find the mount for $path * * @param string $path - * @return MountPoint + * @return IMountPoint */ - public function find(string $path): MountPoint { + public function find(string $path): IMountPoint { $this->setupManager->setupForPath($path); $path = Filesystem::normalizePath($path); @@ -127,7 +129,7 @@ public function find(string $path): MountPoint { * Find all mounts in $path * * @param string $path - * @return MountPoint[] + * @return IMountPoint[] */ public function findIn(string $path): array { $this->setupManager->setupForPath($path); @@ -160,7 +162,7 @@ public function clear() { * Find mounts by storage id * * @param string $id - * @return MountPoint[] + * @return IMountPoint[] */ public function findByStorageId(string $id): array { \OC_Util::setupFS(); @@ -177,7 +179,7 @@ public function findByStorageId(string $id): array { } /** - * @return MountPoint[] + * @return IMountPoint[] */ public function getAll(): array { return $this->mounts; @@ -187,7 +189,7 @@ public function getAll(): array { * Find mounts by numeric storage id * * @param int $id - * @return MountPoint[] + * @return IMountPoint[] */ public function findByNumericId(int $id): array { $storageId = \OC\Files\Cache\Storage::getStorageId($id); From d81713e5c10baf8e14f9a8c4906d0255b18cbb1f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 2 Mar 2022 19:38:21 +0100 Subject: [PATCH 7/9] simplify setup of circular SetupManager<->Manager Signed-off-by: Robin Appelman --- .../tests/PersonalMountTest.php | 8 +-- .../tests/External/ManagerTest.php | 8 +-- lib/private/Files/Mount/Manager.php | 15 ++--- lib/private/Files/SetupManagerFactory.php | 58 +++++++++++++++++++ tests/lib/Files/Mount/ManagerTest.php | 8 +-- 5 files changed, 68 insertions(+), 29 deletions(-) create mode 100644 lib/private/Files/SetupManagerFactory.php diff --git a/apps/files_external/tests/PersonalMountTest.php b/apps/files_external/tests/PersonalMountTest.php index ff33f8e21a764..024695b0188d0 100644 --- a/apps/files_external/tests/PersonalMountTest.php +++ b/apps/files_external/tests/PersonalMountTest.php @@ -25,6 +25,7 @@ namespace OCA\Files_External\Tests; use OC\Files\Mount\Manager; +use OC\Files\SetupManagerFactory; use OCA\Files_External\Lib\PersonalMount; use OCA\Files_External\Lib\StorageConfig; use OCP\Diagnostics\IEventLogger; @@ -51,12 +52,7 @@ public function testFindByStorageId() { $mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo'); - $mountManager = new Manager( - $this->createMock(IEventLogger::class), - $this->createMock(IMountProviderCollection::class), - $this->createMock(IUserManager::class), - $this->createMock(IEventDispatcher::class) - ); + $mountManager = new Manager($this->createMock(SetupManagerFactory::class)); $mountManager->addMount($mount); $this->assertEquals([$mount], $mountManager->findByStorageId('dummy')); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index b6e9593918c04..307b630970f29 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -32,6 +32,7 @@ use OC\Federation\CloudIdManager; use OC\Files\SetupManager; +use OC\Files\SetupManagerFactory; use OC\Files\Storage\StorageFactory; use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\External\MountProvider; @@ -107,12 +108,7 @@ protected function setUp(): void { $this->uid = $this->getUniqueID('user'); $this->user = $this->createUser($this->uid, ''); - $this->mountManager = new \OC\Files\Mount\Manager( - $this->createMock(IEventLogger::class), - $this->createMock(IMountProviderCollection::class), - $this->createMock(IUserManager::class), - $this->createMock(IEventDispatcher::class) - ); + $this->mountManager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class)); $this->clientService = $this->getMockBuilder(IClientService::class) ->disableOriginalConstructor()->getMock(); $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index fc78d71adb4eb..5544b218658cb 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -26,18 +26,16 @@ * along with this program. If not, see * */ + namespace OC\Files\Mount; use OC\Cache\CappedMemoryCache; use OC\Files\Filesystem; use OC\Files\SetupManager; -use OCP\Diagnostics\IEventLogger; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Config\IMountProviderCollection; +use OC\Files\SetupManagerFactory; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; -use OCP\IUserManager; class Manager implements IMountManager { /** @var MountPoint[] */ @@ -48,15 +46,10 @@ class Manager implements IMountManager { private CappedMemoryCache $inPathCache; private SetupManager $setupManager; - public function __construct( - IEventLogger $eventLogger, - IMountProviderCollection $mountProviderCollection, - IUserManager $userManager, - IEventDispatcher $eventDispatcher - ) { + public function __construct(SetupManagerFactory $setupManagerFactory) { $this->pathCache = new CappedMemoryCache(); $this->inPathCache = new CappedMemoryCache(); - $this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userManager, $eventDispatcher); + $this->setupManager = $setupManagerFactory->create($this); } /** diff --git a/lib/private/Files/SetupManagerFactory.php b/lib/private/Files/SetupManagerFactory.php new file mode 100644 index 0000000000000..21628984256c0 --- /dev/null +++ b/lib/private/Files/SetupManagerFactory.php @@ -0,0 +1,58 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OC\Files; + +use OCP\Diagnostics\IEventLogger; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\IMountProviderCollection; +use OCP\Files\Mount\IMountManager; +use OCP\IUserManager; + +class SetupManagerFactory { + private IEventLogger $eventLogger; + private IMountProviderCollection $mountProviderCollection; + private IUserManager $userManager; + private IEventDispatcher $eventDispatcher; + private ?SetupManager $setupManager; + + public function __construct( + IEventLogger $eventLogger, + IMountProviderCollection $mountProviderCollection, + IUserManager $userManager, + IEventDispatcher $eventDispatcher + ) { + $this->eventLogger = $eventLogger; + $this->mountProviderCollection = $mountProviderCollection; + $this->userManager = $userManager; + $this->eventDispatcher = $eventDispatcher; + $this->setupManager = null; + } + + public function create(IMountManager $mountManager): SetupManager { + if (!$this->setupManager) { + $this->setupManager = new SetupManager($this->eventLogger, $this->mountProviderCollection, $mountManager, $this->userManager, $this->eventDispatcher); + } + return $this->setupManager; + } +} diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php index 159fffc7cb8b6..e834d77b73a81 100644 --- a/tests/lib/Files/Mount/ManagerTest.php +++ b/tests/lib/Files/Mount/ManagerTest.php @@ -8,6 +8,7 @@ namespace Test\Files\Mount; +use OC\Files\SetupManagerFactory; use OC\Files\Storage\Temporary; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; @@ -28,12 +29,7 @@ class ManagerTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->manager = new \OC\Files\Mount\Manager( - $this->createMock(IEventLogger::class), - $this->createMock(IMountProviderCollection::class), - $this->createMock(IUserManager::class), - $this->createMock(IEventDispatcher::class), - ); + $this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class)); } public function testFind() { From 07a7dcb8249c9e25ea7a702e8c932520e2b32de6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 3 Mar 2022 16:36:58 +0100 Subject: [PATCH 8/9] move user mountpoint setup to setupmanager Signed-off-by: Robin Appelman --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + .../Files/Config/MountProviderCollection.php | 10 -- lib/private/Files/Filesystem.php | 109 ++---------------- lib/private/Files/SetupManager.php | 63 +++++++++- lib/private/Files/SetupManagerFactory.php | 12 +- lib/private/Server.php | 2 + 7 files changed, 86 insertions(+), 112 deletions(-) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 6af6559af1188..86efab3ad52b2 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1164,6 +1164,7 @@ '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\\SetupManagerFactory' => $baseDir . '/lib/private/Files/SetupManagerFactory.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 69b00b4e2e789..ea37771d63c37 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1193,6 +1193,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c '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\\SetupManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Files/SetupManagerFactory.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 2ca53d385cff5..cd8a2a2e29f70 100644 --- a/lib/private/Files/Config/MountProviderCollection.php +++ b/lib/private/Files/Config/MountProviderCollection.php @@ -183,16 +183,6 @@ public function registerHomeProvider(IHomeMountProvider $provider) { $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]); } - /** - * Cache mounts for user - * - * @param IUser $user - * @param IMountPoint[] $mountPoints - */ - public function registerMounts(IUser $user, array $mountPoints) { - $this->mountCache->registerMounts($user, $mountPoints); - } - /** * Get the mount cache which can be used to search for mounts without setting up the filesystem * diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 71a6385bce166..b392b1aa3cbe3 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -41,6 +41,7 @@ use OC\Files\Config\MountProviderCollection; use OC\Files\Mount\MountPoint; use OC\Lockdown\Filesystem\NullStorage; +use OC\User\NoUserException; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; use OCP\Files\Events\Node\FilesystemTornDownEvent; @@ -367,106 +368,16 @@ public static function initMountManager() { * @throws \OC\User\NoUserException if the user is not available */ public static function initMountPoints($user = '') { - $userManager = \OC::$server->getUserManager(); - if (is_string($user)) { - if ($user === '') { - $user = \OC_User::getUser(); - } - - $userObject = $userManager->get($user); - } elseif ($user instanceof IUser) { - $userObject = $user; - $user = $userObject->getUID(); + /** @var IUserManager $userManager */ + $userManager = \OC::$server->get(IUserManager::class); + + $userObject = ($user instanceof IUser) ? $user : $userManager->get($user); + if ($userObject) { + /** @var SetupManager $setupManager */ + $setupManager = \OC::$server->get(SetupManager::class); + $setupManager->setupForUser($userObject); } else { - $userObject = null; - } - - if ($userObject === null || $user === false || $user === '') { - throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); - } - - if (isset(self::$usersSetup[$user])) { - return; - } - - self::$usersSetup[$user] = true; - - if (is_null($userObject)) { - \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, ILogger::ERROR); - // reset flag, this will make it possible to rethrow the exception if called again - unset(self::$usersSetup[$user]); - throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); - } - - $realUid = $userObject->getUID(); - // workaround in case of different casings - if ($user !== $realUid) { - $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); - \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, ILogger::WARN); - $user = $realUid; - - // again with the correct casing - if (isset(self::$usersSetup[$user])) { - return; - } - - self::$usersSetup[$user] = true; - } - - if (\OC::$server->getLockdownManager()->canAccessFilesystem()) { - /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ - $mountConfigManager = \OC::$server->getMountProviderCollection(); - - // home mounts are handled seperate since we need to ensure this is mounted before we call the other mount providers - $homeMount = $mountConfigManager->getHomeMountForUser($userObject); - self::getMountManager()->addMount($homeMount); - - if ($homeMount->getStorageRootId() === -1) { - $homeMount->getStorage()->mkdir(''); - $homeMount->getStorage()->getScanner()->scan(''); - } - - \OC\Files\Filesystem::getStorage($user); - - // Chance to mount for other storages - if ($userObject) { - $mounts = $mountConfigManager->addMountForUser($userObject, self::getMountManager()); - $mounts[] = $homeMount; - $mountConfigManager->registerMounts($userObject, $mounts); - } - - self::listenForNewMountProviders($mountConfigManager, $userManager); - } else { - self::getMountManager()->addMount(new MountPoint( - new NullStorage([]), - '/' . $user - )); - self::getMountManager()->addMount(new MountPoint( - new NullStorage([]), - '/' . $user . '/files' - )); - } - \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user]); - } - - /** - * Get mounts from mount providers that are registered after setup - * - * @param MountProviderCollection $mountConfigManager - * @param IUserManager $userManager - */ - private static function listenForNewMountProviders(MountProviderCollection $mountConfigManager, IUserManager $userManager) { - if (!self::$listeningForProviders) { - self::$listeningForProviders = true; - $mountConfigManager->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) use ($userManager) { - foreach (Filesystem::$usersSetup as $user => $setup) { - $userObject = $userManager->get($user); - if ($userObject) { - $mounts = $provider->getMountsForUser($userObject, Filesystem::getLoader()); - array_walk($mounts, [self::$mounts, 'addMount']); - } - } - }); + throw new NoUserException(); } } diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 79622132208f0..853c50884a2ad 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -23,6 +23,8 @@ namespace OC\Files; +use OC\Files\Config\MountProviderCollection; +use OC\Files\Mount\MountPoint; use OC\Files\ObjectStore\HomeObjectStoreStorage; use OC\Files\Storage\Common; use OC\Files\Storage\Home; @@ -31,19 +33,24 @@ use OC\Files\Storage\Wrapper\Encoding; use OC\Files\Storage\Wrapper\PermissionsMask; use OC\Files\Storage\Wrapper\Quota; +use OC\Lockdown\Filesystem\NullStorage; use OC_App; use OC_Hook; use OC_Util; use OCP\Constants; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\IMountProvider; use OCP\Files\Config\IMountProviderCollection; +use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorage; +use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; +use OCP\Lockdown\ILockdownManager; class SetupManager { private bool $rootSetup = false; @@ -53,19 +60,27 @@ class SetupManager { private IUserManager $userManager; private array $setupUsers = []; private IEventDispatcher $eventDispatcher; + private IUserMountCache $userMountCache; + private ILockdownManager $lockdownManager; + private bool $listeningForProviders; public function __construct( IEventLogger $eventLogger, IMountProviderCollection $mountProviderCollection, IMountManager $mountManager, IUserManager $userManager, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher, + IUserMountCache $userMountCache, + ILockdownManager $lockdownManager ) { $this->eventLogger = $eventLogger; $this->mountProviderCollection = $mountProviderCollection; $this->mountManager = $mountManager; $this->userManager = $userManager; $this->eventDispatcher = $eventDispatcher; + $this->userMountCache = $userMountCache; + $this->lockdownManager = $lockdownManager; + $this->listeningForProviders = false; } private function setupBuiltinWrappers() { @@ -161,6 +176,34 @@ public function setupForUser(IUser $user): void { Filesystem::init($user, $userDir); + if ($this->lockdownManager->canAccessFilesystem()) { + // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers + $homeMount = $this->mountProviderCollection->getHomeMountForUser($user); + $this->mountManager->addMount($homeMount); + + if ($homeMount->getStorageRootId() === -1) { + $homeMount->getStorage()->mkdir(''); + $homeMount->getStorage()->getScanner()->scan(''); + } + + // Chance to mount for other storages + $mounts = $this->mountProviderCollection->addMountForUser($user, $this->mountManager); + $mounts[] = $homeMount; + $this->userMountCache->registerMounts($user, $mounts); + + $this->listenForNewMountProviders(); + } else { + $this->mountManager->addMount(new MountPoint( + new NullStorage([]), + '/' . $user->getUID() + )); + $this->mountManager->addMount(new MountPoint( + new NullStorage([]), + '/' . $user->getUID() . '/files' + )); + } + \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]); + OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]); $this->eventLogger->end('setup_fs'); @@ -221,4 +264,22 @@ public function tearDown() { $this->mountManager->clear(); $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent()); } + + /** + * Get mounts from mount providers that are registered after setup + */ + private function listenForNewMountProviders() { + if (!$this->listeningForProviders) { + $this->listeningForProviders = true; + $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) { + foreach ($this->setupUsers as $userId) { + $user = $this->userManager->get($userId); + if ($user) { + $mounts = $provider->getMountsForUser($user, Filesystem::getLoader()); + array_walk($mounts, [$this->mountManager, 'addMount']); + } + } + }); + } + } } diff --git a/lib/private/Files/SetupManagerFactory.php b/lib/private/Files/SetupManagerFactory.php index 21628984256c0..5dd1601570d03 100644 --- a/lib/private/Files/SetupManagerFactory.php +++ b/lib/private/Files/SetupManagerFactory.php @@ -26,32 +26,40 @@ use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProviderCollection; +use OCP\Files\Config\IUserMountCache; use OCP\Files\Mount\IMountManager; use OCP\IUserManager; +use OCP\Lockdown\ILockdownManager; class SetupManagerFactory { private IEventLogger $eventLogger; private IMountProviderCollection $mountProviderCollection; private IUserManager $userManager; private IEventDispatcher $eventDispatcher; + private IUserMountCache $userMountCache; + private ILockdownManager $lockdownManager; private ?SetupManager $setupManager; public function __construct( IEventLogger $eventLogger, IMountProviderCollection $mountProviderCollection, IUserManager $userManager, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher, + IUserMountCache $userMountCache, + ILockdownManager $lockdownManager ) { $this->eventLogger = $eventLogger; $this->mountProviderCollection = $mountProviderCollection; $this->userManager = $userManager; $this->eventDispatcher = $eventDispatcher; + $this->userMountCache = $userMountCache; + $this->lockdownManager = $lockdownManager; $this->setupManager = null; } public function create(IMountManager $mountManager): SetupManager { if (!$this->setupManager) { - $this->setupManager = new SetupManager($this->eventLogger, $this->mountProviderCollection, $mountManager, $this->userManager, $this->eventDispatcher); + $this->setupManager = new SetupManager($this->eventLogger, $this->mountProviderCollection, $mountManager, $this->userManager, $this->eventDispatcher, $this->userMountCache, $this->lockdownManager); } return $this->setupManager; } diff --git a/lib/private/Server.php b/lib/private/Server.php index 6101c9a0a612f..38720ab71c013 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -217,6 +217,7 @@ use OCP\LDAP\ILDAPProvider; use OCP\LDAP\ILDAPProviderFactory; use OCP\Lock\ILockingProvider; +use OCP\Lockdown\ILockdownManager; use OCP\Log\ILogFactory; use OCP\Mail\IMailer; use OCP\Remote\Api\IApiFactory; @@ -1093,6 +1094,7 @@ public function __construct($webRoot, \OC\Config $config) { /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); $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(); From 917c74e214094e321ff96e1aa067ae60d22e2c58 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 3 Mar 2022 17:15:02 +0100 Subject: [PATCH 9/9] type fixes Signed-off-by: Robin Appelman --- apps/files_sharing/lib/Updater.php | 2 ++ lib/private/Cache/CappedMemoryCache.php | 4 ++-- lib/private/Files/Filesystem.php | 16 ++-------------- lib/private/Files/Mount/Manager.php | 8 ++++---- lib/private/Files/Node/Root.php | 10 +++++----- lib/private/Files/SetupManager.php | 6 ++---- lib/private/Files/View.php | 16 ++++------------ .../Events/Node/FilesystemTornDownEvent.php | 2 ++ tests/lib/Files/Mount/ManagerTest.php | 4 ---- 9 files changed, 23 insertions(+), 45 deletions(-) diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php index 9ce114f495d71..ad194dde01610 100644 --- a/apps/files_sharing/lib/Updater.php +++ b/apps/files_sharing/lib/Updater.php @@ -26,6 +26,7 @@ */ namespace OCA\Files_Sharing; +use OC\Files\Mount\MountPoint; use OCP\Constants; use OCP\Share\IShare; @@ -105,6 +106,7 @@ private static function renameChildren($oldPath, $newPath) { $mountManager = \OC\Files\Filesystem::getMountManager(); $mountedShares = $mountManager->findIn('/' . \OC_User::getUser() . '/files/' . $oldPath); foreach ($mountedShares as $mount) { + /** @var MountPoint $mount */ if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { $mountPoint = $mount->getMountPoint(); $target = str_replace($absOldPath, $absNewPath, $mountPoint); diff --git a/lib/private/Cache/CappedMemoryCache.php b/lib/private/Cache/CappedMemoryCache.php index dd7cb32e90fa6..9260bf1f6b325 100644 --- a/lib/private/Cache/CappedMemoryCache.php +++ b/lib/private/Cache/CappedMemoryCache.php @@ -51,7 +51,7 @@ public function get($key) { /** * @param string $key - * @param T$value + * @param T $value * @param int $ttl * @return bool */ @@ -89,7 +89,7 @@ public function &offsetGet($offset) { /** * @param string $key - * @param T$value + * @param T $value * @return void */ public function offsetSet($offset, $value): void { diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index b392b1aa3cbe3..1aedad93aa10e 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -38,16 +38,12 @@ namespace OC\Files; use OC\Cache\CappedMemoryCache; -use OC\Files\Config\MountProviderCollection; use OC\Files\Mount\MountPoint; -use OC\Lockdown\Filesystem\NullStorage; use OC\User\NoUserException; use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Config\IMountProvider; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\NotFoundException; use OCP\Files\Storage\IStorageFactory; -use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; @@ -262,11 +258,7 @@ public static function getMountPoint($path) { \OC_Util::setupFS(); } $mount = self::$mounts->find($path); - if ($mount) { - return $mount->getMountPoint(); - } else { - return ''; - } + return $mount->getMountPoint(); } /** @@ -322,11 +314,7 @@ public static function getMountByNumericId($id) { */ public static function resolvePath($path) { $mount = self::getMountManager()->find($path); - if ($mount) { - return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')]; - } else { - return [null, null]; - } + return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')]; } public static function init($user, $root) { diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 5544b218658cb..6683269036327 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -105,10 +105,8 @@ public function find(string $path): IMountPoint { if (isset($this->mounts[$mountPoint])) { $this->pathCache[$path] = $this->mounts[$mountPoint]; return $this->mounts[$mountPoint]; - } - - if ($current === '') { - throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts))); + } elseif ($current === '') { + break; } $current = dirname($current); @@ -116,6 +114,8 @@ public function find(string $path): IMountPoint { $current = ''; } } + + throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts))); } /** diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 4e4dc0ec0de8f..88ac4a31d34e1 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -271,21 +271,21 @@ public function getInternalPath() { * @return int */ public function getId() { - return null; + return 0; } /** * @return array */ public function stat() { - return null; + return []; } /** * @return int */ public function getMTime() { - return null; + return 0; } /** @@ -293,14 +293,14 @@ public function getMTime() { * @return int */ public function getSize($includeMounts = true) { - return null; + return 0; } /** * @return string */ public function getEtag() { - return null; + return ''; } /** diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 853c50884a2ad..f9276ef41718b 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -41,13 +41,11 @@ use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; -use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorage; -use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; use OCP\Lockdown\ILockdownManager; @@ -55,7 +53,7 @@ class SetupManager { private bool $rootSetup = false; private IEventLogger $eventLogger; - private IMountProviderCollection $mountProviderCollection; + private MountProviderCollection $mountProviderCollection; private IMountManager $mountManager; private IUserManager $userManager; private array $setupUsers = []; @@ -66,7 +64,7 @@ class SetupManager { public function __construct( IEventLogger $eventLogger, - IMountProviderCollection $mountProviderCollection, + MountProviderCollection $mountProviderCollection, IMountManager $mountManager, IUserManager $userManager, IEventDispatcher $eventDispatcher, diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 6f96f91178546..779e0611591fe 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -274,7 +274,7 @@ public function mkdir($path) { /** * remove mount point * - * @param \OC\Files\Mount\MoveableMount $mount + * @param IMountPoint $mount * @param string $path relative to data/ * @return boolean */ @@ -719,7 +719,7 @@ public function unlink($path) { $postFix = (substr($path, -1) === '/') ? '/' : ''; $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); $mount = Filesystem::getMountManager()->find($absolutePath . $postFix); - if ($mount and $mount->getInternalPath($absolutePath) === '') { + if ($mount->getInternalPath($absolutePath) === '') { return $this->removeMount($mount, $absolutePath); } if ($this->is_dir($path)) { @@ -1383,10 +1383,6 @@ public function getFileInfo($path, $includeMountPoints = true) { $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); $mount = Filesystem::getMountManager()->find($path); - if (!$mount) { - \OC::$server->getLogger()->warning('Mountpoint not found for path: ' . $path); - return false; - } $storage = $mount->getStorage(); $internalPath = $mount->getInternalPath($path); if ($storage) { @@ -1488,7 +1484,7 @@ public function getDirectoryContent($directory, $mimetype_filter = '') { $rootEntry = $subCache->get(''); if (!$rootEntry) { - $subScanner = $subStorage->getScanner(''); + $subScanner = $subStorage->getScanner(); try { $subScanner->scanFile(''); } catch (\OCP\Files\StorageNotAvailableException $e) { @@ -1916,14 +1912,10 @@ private function getParents($path) { * @param string $absolutePath absolute path * @param bool $useParentMount true to return parent mount instead of whatever * is mounted directly on the given path, false otherwise - * @return \OC\Files\Mount\MountPoint mount point for which to apply locks + * @return IMountPoint mount point for which to apply locks */ private function getMountForLock($absolutePath, $useParentMount = false) { - $results = []; $mount = Filesystem::getMountManager()->find($absolutePath); - if (!$mount) { - return $results; - } if ($useParentMount) { // find out if something is mounted directly on the path diff --git a/lib/public/Files/Events/Node/FilesystemTornDownEvent.php b/lib/public/Files/Events/Node/FilesystemTornDownEvent.php index d8e289a0a9f03..3e7780c827e31 100644 --- a/lib/public/Files/Events/Node/FilesystemTornDownEvent.php +++ b/lib/public/Files/Events/Node/FilesystemTornDownEvent.php @@ -27,6 +27,8 @@ /** * Event fired after the filesystem has been torn down + * + * @since 24.0.0 */ class FilesystemTornDownEvent extends Event { } diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php index e834d77b73a81..f69f8b239bbcc 100644 --- a/tests/lib/Files/Mount/ManagerTest.php +++ b/tests/lib/Files/Mount/ManagerTest.php @@ -10,10 +10,6 @@ use OC\Files\SetupManagerFactory; use OC\Files\Storage\Temporary; -use OCP\Diagnostics\IEventLogger; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\Files\Config\IMountProviderCollection; -use OCP\IUserManager; class LongId extends Temporary { public function getId() {