aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Config/ConfigAdapter.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Config/ConfigAdapter.php')
-rw-r--r--apps/files_external/lib/Config/ConfigAdapter.php118
1 files changed, 49 insertions, 69 deletions
diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php
index 2528c090d66..a46c0fd5c66 100644
--- a/apps/files_external/lib/Config/ConfigAdapter.php
+++ b/apps/files_external/lib/Config/ConfigAdapter.php
@@ -1,93 +1,71 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @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 OCA\Files_External\Config;
+use OC\Files\Cache\Storage;
use OC\Files\Storage\FailedStorage;
use OC\Files\Storage\Wrapper\Availability;
+use OC\Files\Storage\Wrapper\KnownMtime;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
-use OCA\Files_External\Migration\StorageMigrator;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
+use OCP\AppFramework\QueryException;
use OCP\Files\Config\IMountProvider;
-use OCP\Files\Storage;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\ObjectStore\IObjectStore;
+use OCP\Files\Storage\IConstructableStorage;
+use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;
use OCP\Files\StorageNotAvailableException;
use OCP\IUser;
+use OCP\Server;
+use Psr\Clock\ClockInterface;
+use Psr\Log\LoggerInterface;
/**
* Make the old files_external config work with the new public mount config api
*/
class ConfigAdapter implements IMountProvider {
-
- /** @var UserStoragesService */
- private $userStoragesService;
-
- /** @var UserGlobalStoragesService */
- private $userGlobalStoragesService;
- /** @var StorageMigrator */
- private $migrator;
+ public function __construct(
+ private UserStoragesService $userStoragesService,
+ private UserGlobalStoragesService $userGlobalStoragesService,
+ private ClockInterface $clock,
+ ) {
+ }
/**
- * @param UserStoragesService $userStoragesService
- * @param UserGlobalStoragesService $userGlobalStoragesService
- * @param StorageMigrator $migrator
+ * @param class-string $class
+ * @return class-string<IObjectStore>
+ * @throws \InvalidArgumentException
+ * @psalm-taint-escape callable
*/
- public function __construct(
- UserStoragesService $userStoragesService,
- UserGlobalStoragesService $userGlobalStoragesService,
- StorageMigrator $migrator
- ) {
- $this->userStoragesService = $userStoragesService;
- $this->userGlobalStoragesService = $userGlobalStoragesService;
- $this->migrator = $migrator;
+ private function validateObjectStoreClassString(string $class): string {
+ if (!\is_subclass_of($class, IObjectStore::class)) {
+ throw new \InvalidArgumentException('Invalid object store');
+ }
+ return $class;
}
/**
* Process storage ready for mounting
*
- * @param StorageConfig $storage
- * @param IUser $user
- * @throws \OCP\AppFramework\QueryException
+ * @throws QueryException
*/
- private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
+ private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void {
foreach ($storage->getBackendOptions() as $option => $value) {
- $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
+ $storage->setBackendOption($option, MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
}
$objectStore = $storage->getBackendOption('objectstore');
if ($objectStore) {
- $objectClass = $objectStore['class'];
- if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
- throw new \InvalidArgumentException('Invalid object store');
- }
+ $objectClass = $this->validateObjectStoreClassString($objectStore['class']);
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
}
@@ -99,10 +77,12 @@ class ConfigAdapter implements IMountProvider {
* Construct the storage implementation
*
* @param StorageConfig $storageConfig
- * @return Storage
*/
- private function constructStorage(StorageConfig $storageConfig) {
+ private function constructStorage(StorageConfig $storageConfig): IStorage {
$class = $storageConfig->getBackend()->getStorageClass();
+ if (!is_a($class, IConstructableStorage::class, true)) {
+ Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0', ['class' => $class]);
+ }
$storage = new $class($storageConfig->getBackendOptions());
// auth mechanism should fire first
@@ -115,13 +95,9 @@ class ConfigAdapter implements IMountProvider {
/**
* Get all mountpoints applicable for the user
*
- * @param \OCP\IUser $user
- * @param \OCP\Files\Storage\IStorageFactory $loader
- * @return \OCP\Files\Mount\IMountPoint[]
+ * @return IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
- $this->migrator->migrateUser($user);
-
$this->userStoragesService->setUser($user);
$this->userGlobalStoragesService->setUser($user);
@@ -138,11 +114,11 @@ class ConfigAdapter implements IMountProvider {
}, $storageConfigs);
- \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
+ Storage::getGlobalCache()->loadForStorageIds(array_map(function (IStorage $storage) {
return $storage->getId();
}, $storages));
- $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
+ $availableStorages = array_map(function (IStorage $storage, StorageConfig $storageConfig): IStorage {
try {
$availability = $storage->getAvailability();
if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
@@ -157,13 +133,17 @@ class ConfigAdapter implements IMountProvider {
return $storage;
}, $storages, $storageConfigs);
- $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
- if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
+ $mounts = array_map(function (StorageConfig $storageConfig, IStorage $storage) use ($user, $loader) {
+ $storage->setOwner($user->getUID());
+ if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) {
return new PersonalMount(
$this->userStoragesService,
$storageConfig,
$storageConfig->getId(),
- $storage,
+ new KnownMtime([
+ 'storage' => $storage,
+ 'clock' => $this->clock,
+ ]),
'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
null,
$loader,
@@ -171,7 +151,7 @@ class ConfigAdapter implements IMountProvider {
$storageConfig->getId()
);
} else {
- return new ExternalMountPoint(
+ return new SystemMountPoint(
$storageConfig,
$storage,
'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),