diff options
Diffstat (limited to 'lib/private/Files/Mount')
-rw-r--r-- | lib/private/Files/Mount/CacheMountProvider.php | 29 | ||||
-rw-r--r-- | lib/private/Files/Mount/HomeMountPoint.php | 34 | ||||
-rw-r--r-- | lib/private/Files/Mount/LocalHomeMountProvider.php | 25 | ||||
-rw-r--r-- | lib/private/Files/Mount/Manager.php | 133 | ||||
-rw-r--r-- | lib/private/Files/Mount/MountPoint.php | 103 | ||||
-rw-r--r-- | lib/private/Files/Mount/MoveableMount.php | 29 | ||||
-rw-r--r-- | lib/private/Files/Mount/ObjectHomeMountProvider.php | 136 | ||||
-rw-r--r-- | lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php | 39 | ||||
-rw-r--r-- | lib/private/Files/Mount/RootMountProvider.php | 50 |
9 files changed, 276 insertions, 302 deletions
diff --git a/lib/private/Files/Mount/CacheMountProvider.php b/lib/private/Files/Mount/CacheMountProvider.php index 8e632642a75..27c7eec9da3 100644 --- a/lib/private/Files/Mount/CacheMountProvider.php +++ b/lib/private/Files/Mount/CacheMountProvider.php @@ -1,25 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\Files\Mount; use OCP\Files\Config\IMountProvider; @@ -53,7 +38,7 @@ class CacheMountProvider implements IMountProvider { * @return \OCP\Files\Mount\IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $loader) { - $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); + $cacheBaseDir = $this->config->getSystemValueString('cache_path', ''); if ($cacheBaseDir !== '') { $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); if (!file_exists($cacheDir)) { @@ -62,8 +47,8 @@ class CacheMountProvider implements IMountProvider { } return [ - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]), - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads', $loader]) + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class), + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class) ]; } else { return []; diff --git a/lib/private/Files/Mount/HomeMountPoint.php b/lib/private/Files/Mount/HomeMountPoint.php new file mode 100644 index 00000000000..5a648f08c89 --- /dev/null +++ b/lib/private/Files/Mount/HomeMountPoint.php @@ -0,0 +1,34 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OC\Files\Mount; + +use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; + +class HomeMountPoint extends MountPoint { + private IUser $user; + + public function __construct( + IUser $user, + $storage, + string $mountpoint, + ?array $arguments = null, + ?IStorageFactory $loader = null, + ?array $mountOptions = null, + ?int $mountId = null, + ?string $mountProvider = null, + ) { + parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, $mountProvider); + $this->user = $user; + } + + public function getUser(): IUser { + return $this->user; + } +} diff --git a/lib/private/Files/Mount/LocalHomeMountProvider.php b/lib/private/Files/Mount/LocalHomeMountProvider.php index 68c69cc8cdc..a2b3d3b2a99 100644 --- a/lib/private/Files/Mount/LocalHomeMountProvider.php +++ b/lib/private/Files/Mount/LocalHomeMountProvider.php @@ -1,25 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\Files\Mount; use OCP\Files\Config\IHomeMountProvider; @@ -39,6 +24,6 @@ class LocalHomeMountProvider implements IHomeMountProvider { */ public function getHomeMountForUser(IUser $user, IStorageFactory $loader) { $arguments = ['user' => $user]; - return new MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader); + return new HomeMountPoint($user, '\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader, null, null, self::class); } } diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index f3fa77a394c..55de488c726 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -1,52 +1,35 @@ <?php declare(strict_types=1); - /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\Files\Mount; -use OC\Cache\CappedMemoryCache; use OC\Files\Filesystem; +use OC\Files\SetupManager; +use OC\Files\SetupManagerFactory; +use OCP\Cache\CappedMemoryCache; +use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; +use OCP\Files\NotFoundException; class Manager implements IMountManager { /** @var MountPoint[] */ - private $mounts = []; - - /** @var CappedMemoryCache */ - private $pathCache; - - /** @var CappedMemoryCache */ - private $inPathCache; - - public function __construct() { + private array $mounts = []; + /** @var CappedMemoryCache<IMountPoint> */ + private CappedMemoryCache $pathCache; + /** @var CappedMemoryCache<IMountPoint[]> */ + private CappedMemoryCache $inPathCache; + private SetupManager $setupManager; + + public function __construct(SetupManagerFactory $setupManagerFactory) { $this->pathCache = new CappedMemoryCache(); $this->inPathCache = new CappedMemoryCache(); + $this->setupManager = $setupManagerFactory->create($this); } /** @@ -86,26 +69,33 @@ class Manager implements IMountManager { * Find the mount for $path * * @param string $path - * @return MountPoint|null + * @return IMountPoint */ - public function find(string $path) { - \OC_Util::setupFS(); + public function find(string $path): IMountPoint { + $this->setupManager->setupForPath($path); $path = Filesystem::normalizePath($path); if (isset($this->pathCache[$path])) { return $this->pathCache[$path]; } + + + if (count($this->mounts) === 0) { + $this->setupManager->setupRoot(); + if (count($this->mounts) === 0) { + throw new \Exception('No mounts even after explicitly setting up the root mounts'); + } + } + $current = $path; while (true) { $mountPoint = $current . '/'; if (isset($this->mounts[$mountPoint])) { $this->pathCache[$path] = $this->mounts[$mountPoint]; return $this->mounts[$mountPoint]; - } - - if ($current === '') { - return null; + } elseif ($current === '') { + break; } $current = dirname($current); @@ -113,16 +103,18 @@ class Manager implements IMountManager { $current = ''; } } + + throw new NotFoundException('No mount for path ' . $path . ' existing mounts (' . count($this->mounts) . '): ' . implode(',', array_keys($this->mounts))); } /** * Find all mounts in $path * * @param string $path - * @return MountPoint[] + * @return IMountPoint[] */ public function findIn(string $path): array { - \OC_Util::setupFS(); + $this->setupManager->setupForPath($path, true); $path = $this->formatPath($path); if (isset($this->inPathCache[$path])) { @@ -152,10 +144,9 @@ class Manager implements IMountManager { * Find mounts by storage id * * @param string $id - * @return MountPoint[] + * @return IMountPoint[] */ public function findByStorageId(string $id): array { - \OC_Util::setupFS(); if (\strlen($id) > 64) { $id = md5($id); } @@ -169,7 +160,7 @@ class Manager implements IMountManager { } /** - * @return MountPoint[] + * @return IMountPoint[] */ public function getAll(): array { return $this->mounts; @@ -179,11 +170,16 @@ class Manager implements IMountManager { * 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); - return $this->findByStorageId($storageId); + $result = []; + foreach ($this->mounts as $mount) { + if ($mount->getNumericStorageId() === $id) { + $result[] = $mount; + } + } + return $result; } /** @@ -197,4 +193,43 @@ class Manager implements IMountManager { } return $path; } + + public function getSetupManager(): SetupManager { + return $this->setupManager; + } + + /** + * Return all mounts in a path from a specific mount provider + * + * @param string $path + * @param string[] $mountProviders + * @return MountPoint[] + */ + public function getMountsByMountProvider(string $path, array $mountProviders) { + $this->getSetupManager()->setupForProvider($path, $mountProviders); + if (in_array('', $mountProviders)) { + return $this->mounts; + } else { + return array_filter($this->mounts, function ($mount) use ($mountProviders) { + return in_array($mount->getMountProvider(), $mountProviders); + }); + } + } + + /** + * Return the mount matching a cached mount info (or mount file info) + * + * @param ICachedMountInfo $info + * + * @return IMountPoint|null + */ + public function getMountFromMountInfo(ICachedMountInfo $info): ?IMountPoint { + $this->setupManager->setupForPath($info->getMountPoint()); + foreach ($this->mounts as $mount) { + if ($mount->getMountPoint() === $info->getMountPoint()) { + return $mount; + } + } + return null; + } } diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index cbf3785c409..bab2dc8e4bd 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -1,49 +1,27 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\Files\Mount; use OC\Files\Filesystem; use OC\Files\Storage\Storage; use OC\Files\Storage\StorageFactory; use OCP\Files\Mount\IMountPoint; -use OCP\ILogger; +use OCP\Files\Storage\IStorageFactory; +use Psr\Log\LoggerInterface; class MountPoint implements IMountPoint { /** - * @var \OC\Files\Storage\Storage $storage + * @var \OC\Files\Storage\Storage|null $storage */ protected $storage = null; protected $class; protected $storageId; + protected $numericStorageId = null; protected $rootId = null; /** @@ -77,6 +55,9 @@ class MountPoint implements IMountPoint { /** @var int|null */ protected $mountId; + /** @var string */ + protected $mountProvider; + /** * @param string|\OC\Files\Storage\Storage $storage * @param string $mountpoint @@ -84,9 +65,18 @@ class MountPoint implements IMountPoint { * @param \OCP\Files\Storage\IStorageFactory $loader * @param array $mountOptions mount specific options * @param int|null $mountId + * @param string|null $mountProvider * @throws \Exception */ - public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { + public function __construct( + $storage, + string $mountpoint, + ?array $arguments = null, + ?IStorageFactory $loader = null, + ?array $mountOptions = null, + ?int $mountId = null, + ?string $mountProvider = null, + ) { if (is_null($arguments)) { $arguments = []; } @@ -108,12 +98,18 @@ class MountPoint implements IMountPoint { $this->storage = $this->loader->wrap($this, $storage); } else { // Update old classes to new namespace - if (strpos($storage, 'OC_Filestorage_') !== false) { + if (str_contains($storage, 'OC_Filestorage_')) { $storage = '\OC\Files\Storage\\' . substr($storage, 15); } $this->class = $storage; $this->arguments = $arguments; } + if ($mountProvider) { + if (strlen($mountProvider) > 128) { + throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters"); + } + } + $this->mountProvider = $mountProvider ?? ''; } /** @@ -155,19 +151,19 @@ class MountPoint implements IMountPoint { // the root storage could not be initialized, show the user! throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception); } else { - \OC::$server->getLogger()->logException($exception, ['level' => ILogger::ERROR]); + \OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception]); } return; } } else { - \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', ILogger::ERROR); + \OC::$server->get(LoggerInterface::class)->error('Storage backend ' . $this->class . ' not found', ['app' => 'core']); $this->invalidStorage = true; return; } } /** - * @return \OC\Files\Storage\Storage + * @return \OC\Files\Storage\Storage|null */ public function getStorage() { if (is_null($this->storage)) { @@ -177,19 +173,15 @@ class MountPoint implements IMountPoint { } /** - * @return string + * @return string|null */ public function getStorageId() { if (!$this->storageId) { - if (is_null($this->storage)) { - $storage = $this->createStorage(); //FIXME: start using exceptions - if (is_null($storage)) { - return null; - } - - $this->storage = $storage; + $storage = $this->getStorage(); + if (is_null($storage)) { + return null; } - $this->storageId = $this->storage->getId(); + $this->storageId = $storage->getId(); if (strlen($this->storageId) > 64) { $this->storageId = md5($this->storageId); } @@ -201,7 +193,14 @@ class MountPoint implements IMountPoint { * @return int */ public function getNumericStorageId() { - return $this->getStorage()->getStorageCache()->getNumericId(); + if (is_null($this->numericStorageId)) { + $storage = $this->getStorage(); + if (is_null($storage)) { + return -1; + } + $this->numericStorageId = $storage->getCache()->getNumericStorageId(); + } + return $this->numericStorageId; } /** @@ -250,7 +249,7 @@ class MountPoint implements IMountPoint { * @return mixed */ public function getOption($name, $default) { - return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; + return $this->mountOptions[$name] ?? $default; } /** @@ -269,7 +268,13 @@ class MountPoint implements IMountPoint { */ public function getStorageRootId() { if (is_null($this->rootId) || $this->rootId === -1) { - $this->rootId = (int)$this->getStorage()->getCache()->getId(''); + $storage = $this->getStorage(); + // if we can't create the storage return -1 as root id, this is then handled the same as if the root isn't scanned yet + if ($storage === null) { + $this->rootId = -1; + } else { + $this->rootId = (int)$storage->getCache()->getId(''); + } } return $this->rootId; } @@ -281,4 +286,8 @@ class MountPoint implements IMountPoint { public function getMountType() { return ''; } + + public function getMountProvider(): string { + return $this->mountProvider; + } } diff --git a/lib/private/Files/Mount/MoveableMount.php b/lib/private/Files/Mount/MoveableMount.php index 2c9cfc91dad..755733bf651 100644 --- a/lib/private/Files/Mount/MoveableMount.php +++ b/lib/private/Files/Mount/MoveableMount.php @@ -1,32 +1,18 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\Files\Mount; +use OCP\Files\Mount\IMovableMount; + /** * Defines the mount point to be (re)moved by the user */ -interface MoveableMount { +interface MoveableMount extends IMovableMount { /** * Move the mount point to $target * @@ -38,7 +24,6 @@ interface MoveableMount { /** * Remove the mount points * - * @return mixed * @return bool */ public function removeMount(); diff --git a/lib/private/Files/Mount/ObjectHomeMountProvider.php b/lib/private/Files/Mount/ObjectHomeMountProvider.php index 9b243d7f8f2..4b088f2c808 100644 --- a/lib/private/Files/Mount/ObjectHomeMountProvider.php +++ b/lib/private/Files/Mount/ObjectHomeMountProvider.php @@ -1,141 +1,45 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Vlastimil Pecinka <pecinka@email.cz> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OC\Files\Mount; +use OC\Files\ObjectStore\HomeObjectStoreStorage; +use OC\Files\ObjectStore\PrimaryObjectStoreConfig; use OCP\Files\Config\IHomeMountProvider; +use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorageFactory; -use OCP\IConfig; -use OCP\ILogger; use OCP\IUser; /** * Mount provider for object store home storages */ class ObjectHomeMountProvider implements IHomeMountProvider { - /** - * @var IConfig - */ - private $config; - - /** - * ObjectStoreHomeMountProvider constructor. - * - * @param IConfig $config - */ - public function __construct(IConfig $config) { - $this->config = $config; + public function __construct( + private PrimaryObjectStoreConfig $objectStoreConfig, + ) { } /** - * Get the cache mount for a user + * Get the home mount for a user * * @param IUser $user * @param IStorageFactory $loader - * @return \OCP\Files\Mount\IMountPoint - */ - public function getHomeMountForUser(IUser $user, IStorageFactory $loader) { - $config = $this->getMultiBucketObjectStoreConfig($user); - if ($config === null) { - $config = $this->getSingleBucketObjectStoreConfig($user); - } - - if ($config === null) { - return null; - } - - return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader); - } - - /** - * @param IUser $user - * @return array|null + * @return ?IMountPoint */ - private function getSingleBucketObjectStoreConfig(IUser $user) { - $config = $this->config->getSystemValue('objectstore'); - if (!is_array($config)) { + public function getHomeMountForUser(IUser $user, IStorageFactory $loader): ?IMountPoint { + $objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForUser($user); + if ($objectStoreConfig === null) { return null; } + $arguments = array_merge($objectStoreConfig['arguments'], [ + 'objectstore' => $this->objectStoreConfig->buildObjectStore($objectStoreConfig), + 'user' => $user, + ]); - // sanity checks - if (empty($config['class'])) { - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); - } - if (!isset($config['arguments'])) { - $config['arguments'] = []; - } - // instantiate object store implementation - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); - - $config['arguments']['user'] = $user; - - return $config; - } - - /** - * @param IUser $user - * @return array|null - */ - private function getMultiBucketObjectStoreConfig(IUser $user) { - $config = $this->config->getSystemValue('objectstore_multibucket'); - if (!is_array($config)) { - return null; - } - - // sanity checks - if (empty($config['class'])) { - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); - } - if (!isset($config['arguments'])) { - $config['arguments'] = []; - } - - $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); - - if ($bucket === null) { - /* - * Use any provided bucket argument as prefix - * and add the mapping from username => bucket - */ - if (!isset($config['arguments']['bucket'])) { - $config['arguments']['bucket'] = ''; - } - $mapper = new \OC\Files\ObjectStore\Mapper($user); - $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; - $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets); - - $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); - } else { - $config['arguments']['bucket'] = $bucket; - } - - // instantiate object store implementation - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); - - $config['arguments']['user'] = $user; - - return $config; + return new HomeMountPoint($user, HomeObjectStoreStorage::class, '/' . $user->getUID(), $arguments, $loader, null, null, self::class); } } diff --git a/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php b/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php index 4185c9b86a7..1546ef98f50 100644 --- a/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php +++ b/lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php @@ -3,27 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Morris Jobke <hey@morrisjobke.de> - * - * @author Morris Jobke <hey@morrisjobke.de> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OC\Files\Mount; use OC\Files\ObjectStore\AppdataPreviewObjectStoreStorage; @@ -32,18 +14,17 @@ use OC\Files\Storage\Wrapper\Jail; use OCP\Files\Config\IRootMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; /** * Mount provider for object store app data folder for previews */ class ObjectStorePreviewCacheMountProvider implements IRootMountProvider { - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; /** @var IConfig */ private $config; - public function __construct(ILogger $logger, IConfig $config) { + public function __construct(LoggerInterface $logger, IConfig $config) { $this->logger = $logger; $this->config = $config; } @@ -70,7 +51,10 @@ class ObjectStorePreviewCacheMountProvider implements IRootMountProvider { AppdataPreviewObjectStoreStorage::class, '/appdata_' . $instanceId . '/preview/' . $parent . '/' . $child, $this->getMultiBucketObjectStore($i), - $loader + $loader, + null, + null, + self::class ); $i++; } @@ -88,7 +72,10 @@ class ObjectStorePreviewCacheMountProvider implements IRootMountProvider { $fakeRootStorageJail, '/appdata_' . $instanceId . '/preview/old-multibucket', null, - $loader + $loader, + null, + null, + self::class ); return $mountPoints; diff --git a/lib/private/Files/Mount/RootMountProvider.php b/lib/private/Files/Mount/RootMountProvider.php new file mode 100644 index 00000000000..5e0c924ad38 --- /dev/null +++ b/lib/private/Files/Mount/RootMountProvider.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OC\Files\Mount; + +use OC; +use OC\Files\ObjectStore\ObjectStoreStorage; +use OC\Files\ObjectStore\PrimaryObjectStoreConfig; +use OC\Files\Storage\LocalRootStorage; +use OCP\Files\Config\IRootMountProvider; +use OCP\Files\Storage\IStorageFactory; +use OCP\IConfig; + +class RootMountProvider implements IRootMountProvider { + private PrimaryObjectStoreConfig $objectStoreConfig; + private IConfig $config; + + public function __construct(PrimaryObjectStoreConfig $objectStoreConfig, IConfig $config) { + $this->objectStoreConfig = $objectStoreConfig; + $this->config = $config; + } + + public function getRootMounts(IStorageFactory $loader): array { + $objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForRoot(); + + if ($objectStoreConfig) { + return [$this->getObjectStoreRootMount($loader, $objectStoreConfig)]; + } else { + return [$this->getLocalRootMount($loader)]; + } + } + + private function getLocalRootMount(IStorageFactory $loader): MountPoint { + $configDataDirectory = $this->config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data'); + return new MountPoint(LocalRootStorage::class, '/', ['datadir' => $configDataDirectory], $loader, null, null, self::class); + } + + private function getObjectStoreRootMount(IStorageFactory $loader, array $objectStoreConfig): MountPoint { + $arguments = array_merge($objectStoreConfig['arguments'], [ + 'objectstore' => $this->objectStoreConfig->buildObjectStore($objectStoreConfig), + ]); + + return new MountPoint(ObjectStoreStorage::class, '/', $arguments, $loader, null, null, self::class); + } +} |