diff options
Diffstat (limited to 'lib/public/Files/Config')
-rw-r--r-- | lib/public/Files/Config/Event/UserMountAddedEvent.php | 26 | ||||
-rw-r--r-- | lib/public/Files/Config/Event/UserMountRemovedEvent.php | 26 | ||||
-rw-r--r-- | lib/public/Files/Config/Event/UserMountUpdatedEvent.php | 27 | ||||
-rw-r--r-- | lib/public/Files/Config/ICachedMountFileInfo.php | 28 | ||||
-rw-r--r-- | lib/public/Files/Config/ICachedMountInfo.php | 80 | ||||
-rw-r--r-- | lib/public/Files/Config/IHomeMountProvider.php | 28 | ||||
-rw-r--r-- | lib/public/Files/Config/IMountProvider.php | 27 | ||||
-rw-r--r-- | lib/public/Files/Config/IMountProviderCollection.php | 84 | ||||
-rw-r--r-- | lib/public/Files/Config/IRootMountProvider.php | 24 | ||||
-rw-r--r-- | lib/public/Files/Config/IUserMountCache.php | 135 |
10 files changed, 485 insertions, 0 deletions
diff --git a/lib/public/Files/Config/Event/UserMountAddedEvent.php b/lib/public/Files/Config/Event/UserMountAddedEvent.php new file mode 100644 index 00000000000..8abd7512188 --- /dev/null +++ b/lib/public/Files/Config/Event/UserMountAddedEvent.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Files\Config\Event; + +use OCP\EventDispatcher\Event; +use OCP\Files\Config\ICachedMountInfo; + +/** + * Event emitted when a user mount was added. + * + * @since 32.0.0 + */ +class UserMountAddedEvent extends Event { + public function __construct( + public readonly ICachedMountInfo $mountPoint, + ) { + parent::__construct(); + } +} diff --git a/lib/public/Files/Config/Event/UserMountRemovedEvent.php b/lib/public/Files/Config/Event/UserMountRemovedEvent.php new file mode 100644 index 00000000000..0de7cfc4a99 --- /dev/null +++ b/lib/public/Files/Config/Event/UserMountRemovedEvent.php @@ -0,0 +1,26 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Files\Config\Event; + +use OCP\EventDispatcher\Event; +use OCP\Files\Config\ICachedMountInfo; + +/** + * Event emitted when a user mount was removed. + * + * @since 32.0.0 + */ +class UserMountRemovedEvent extends Event { + public function __construct( + public readonly ICachedMountInfo $mountPoint, + ) { + parent::__construct(); + } +} diff --git a/lib/public/Files/Config/Event/UserMountUpdatedEvent.php b/lib/public/Files/Config/Event/UserMountUpdatedEvent.php new file mode 100644 index 00000000000..f797bef134e --- /dev/null +++ b/lib/public/Files/Config/Event/UserMountUpdatedEvent.php @@ -0,0 +1,27 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Files\Config\Event; + +use OCP\EventDispatcher\Event; +use OCP\Files\Config\ICachedMountInfo; + +/** + * Event emitted when a user mount was moved. + * + * @since 32.0.0 + */ +class UserMountUpdatedEvent extends Event { + public function __construct( + public readonly ICachedMountInfo $oldMountPoint, + public readonly ICachedMountInfo $newMountPoint, + ) { + parent::__construct(); + } +} diff --git a/lib/public/Files/Config/ICachedMountFileInfo.php b/lib/public/Files/Config/ICachedMountFileInfo.php new file mode 100644 index 00000000000..a9b30d8ba6d --- /dev/null +++ b/lib/public/Files/Config/ICachedMountFileInfo.php @@ -0,0 +1,28 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Files\Config; + +/** + * Holds information about a mount for a user + * + * @since 13.0.0 + */ +interface ICachedMountFileInfo extends ICachedMountInfo { + /** + * Return the path for the file within the cached mount + * + * @return string + * @since 13.0.0 + */ + public function getInternalPath(): string; + + /** + * @return string + * @since 13.0.0 + */ + public function getPath(): string; +} diff --git a/lib/public/Files/Config/ICachedMountInfo.php b/lib/public/Files/Config/ICachedMountInfo.php new file mode 100644 index 00000000000..cb9c0205d3d --- /dev/null +++ b/lib/public/Files/Config/ICachedMountInfo.php @@ -0,0 +1,80 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCP\Files\Config; + +use OCP\Files\Node; +use OCP\IUser; + +/** + * Holds information about a mount for a user + * + * @since 9.0.0 + */ +interface ICachedMountInfo { + /** + * @return IUser + * @since 9.0.0 + */ + public function getUser(): IUser; + + /** + * @return int the numeric storage id of the mount + * @since 9.0.0 + */ + public function getStorageId(): int; + + /** + * @return int the fileid of the root of the mount + * @since 9.0.0 + */ + public function getRootId(): int; + + /** + * @return Node|null the root node of the mount + * @since 9.0.0 + */ + public function getMountPointNode(): ?Node; + + /** + * @return string the mount point of the mount for the user + * @since 9.0.0 + */ + public function getMountPoint(): string; + + /** + * Get the id of the configured mount + * + * @return int|null mount id or null if not applicable + * @since 9.1.0 + */ + public function getMountId(): ?int; + + /** + * Get the internal path (within the storage) of the root of the mount + * + * @return string + * @since 11.0.0 + */ + public function getRootInternalPath(): string; + + /** + * Get the class of the mount provider that this mount originates from + * + * @return string + * @since 24.0.0 + */ + public function getMountProvider(): string; + + /** + * Get a key that uniquely identifies the mount + * + * @return string + * @since 28.0.0 + */ + public function getKey(): string; +} diff --git a/lib/public/Files/Config/IHomeMountProvider.php b/lib/public/Files/Config/IHomeMountProvider.php new file mode 100644 index 00000000000..b193e9ba22e --- /dev/null +++ b/lib/public/Files/Config/IHomeMountProvider.php @@ -0,0 +1,28 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCP\Files\Config; + +use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; + +/** + * Provides + * + * @since 9.1.0 + */ +interface IHomeMountProvider { + /** + * Get all mountpoints applicable for the user + * + * @param \OCP\IUser $user + * @param \OCP\Files\Storage\IStorageFactory $loader + * @return \OCP\Files\Mount\IMountPoint|null + * @since 9.1.0 + */ + public function getHomeMountForUser(IUser $user, IStorageFactory $loader); +} diff --git a/lib/public/Files/Config/IMountProvider.php b/lib/public/Files/Config/IMountProvider.php new file mode 100644 index 00000000000..b59813a866d --- /dev/null +++ b/lib/public/Files/Config/IMountProvider.php @@ -0,0 +1,27 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCP\Files\Config; + +use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; + +/** + * Provides + * @since 8.0.0 + */ +interface IMountProvider { + /** + * Get all mountpoints applicable for the user + * + * @param \OCP\IUser $user + * @param \OCP\Files\Storage\IStorageFactory $loader + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.0.0 + */ + public function getMountsForUser(IUser $user, IStorageFactory $loader); +} diff --git a/lib/public/Files/Config/IMountProviderCollection.php b/lib/public/Files/Config/IMountProviderCollection.php new file mode 100644 index 00000000000..db5188372c1 --- /dev/null +++ b/lib/public/Files/Config/IMountProviderCollection.php @@ -0,0 +1,84 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCP\Files\Config; + +use OCP\IUser; + +/** + * Manages the different mount providers + * @since 8.0.0 + */ +interface IMountProviderCollection { + /** + * Get all configured mount points for the user + * + * @param \OCP\IUser $user + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.0.0 + */ + public function getMountsForUser(IUser $user); + + /** + * Get the configured mount points for the user from a specific mount provider + * + * @param \OCP\IUser $user + * @param class-string<IMountProvider>[] $mountProviderClasses + * @return \OCP\Files\Mount\IMountPoint[] + * @since 24.0.0 + */ + public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array; + + /** + * Get the configured home mount for this user + * + * @param \OCP\IUser $user + * @return \OCP\Files\Mount\IMountPoint + * @since 9.1.0 + */ + public function getHomeMountForUser(IUser $user); + + /** + * Add a provider for mount points + * + * @param \OCP\Files\Config\IMountProvider $provider + * @since 8.0.0 + */ + public function registerProvider(IMountProvider $provider); + + /** + * Add a filter for mounts + * + * @param callable $filter (IMountPoint $mountPoint, IUser $user) => boolean + * @since 14.0.0 + */ + public function registerMountFilter(callable $filter); + + /** + * Add a provider for home mount points + * + * @param \OCP\Files\Config\IHomeMountProvider $provider + * @since 9.1.0 + */ + public function registerHomeProvider(IHomeMountProvider $provider); + + /** + * Get the mount cache which can be used to search for mounts without setting up the filesystem + * + * @return IUserMountCache + * @since 9.0.0 + */ + public function getMountCache(); + + /** + * Get all root mountpoints + * + * @return \OCP\Files\Mount\IMountPoint[] + * @since 20.0.0 + */ + public function getRootMounts(): array; +} diff --git a/lib/public/Files/Config/IRootMountProvider.php b/lib/public/Files/Config/IRootMountProvider.php new file mode 100644 index 00000000000..e2a32fc346a --- /dev/null +++ b/lib/public/Files/Config/IRootMountProvider.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCP\Files\Config; + +use OCP\Files\Storage\IStorageFactory; + +/** + * @since 20.0.0 + */ +interface IRootMountProvider { + /** + * Get all root mountpoints of this provider + * + * @return \OCP\Files\Mount\IMountPoint[] + * @since 20.0.0 + */ + public function getRootMounts(IStorageFactory $loader): array; +} diff --git a/lib/public/Files/Config/IUserMountCache.php b/lib/public/Files/Config/IUserMountCache.php new file mode 100644 index 00000000000..a5b68ded66d --- /dev/null +++ b/lib/public/Files/Config/IUserMountCache.php @@ -0,0 +1,135 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCP\Files\Config; + +use OCP\Files\Mount\IMountPoint; +use OCP\Files\NotFoundException; +use OCP\IUser; + +/** + * Cache mounts points per user in the cache so we can easily look them up + * + * @since 9.0.0 + */ +interface IUserMountCache { + /** + * Register mounts for a user to the cache + * + * @param IUser $user + * @param IMountPoint[] $mounts + * @param array|null $mountProviderClasses + * @since 9.0.0 + */ + public function registerMounts(IUser $user, array $mounts, ?array $mountProviderClasses = null); + + /** + * Get all cached mounts for a user + * + * @param IUser $user + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForUser(IUser $user); + + /** + * Get all cached mounts by storage + * + * @param int $numericStorageId + * @param string|null $user limit the results to a single user @since 12.0.0 + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForStorageId($numericStorageId, $user = null); + + /** + * Get all cached mounts by root + * + * @param int $rootFileId + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForRootId($rootFileId); + + /** + * Get all cached mounts that contain a file + * + * @param int $fileId + * @param string|null $user optionally restrict the results to a single user @since 12.0.0 + * @return ICachedMountFileInfo[] + * @since 9.0.0 + */ + public function getMountsForFileId($fileId, $user = null); + + /** + * Remove all cached mounts for a user + * + * @param IUser $user + * @since 9.0.0 + */ + public function removeUserMounts(IUser $user); + + /** + * Remove all mounts for a user and storage + * + * @param $storageId + * @param string $userId + * @return mixed + * @since 9.0.0 + */ + public function removeUserStorageMount($storageId, $userId); + + /** + * Remove all cached mounts for a storage + * + * @param $storageId + * @return mixed + * @since 9.0.0 + */ + public function remoteStorageMounts($storageId); + + /** + * Get the used space for users + * + * Note that this only includes the space in their home directory, + * not any incoming shares or external storage. + * + * @param IUser[] $users + * @return int[] [$userId => $userSpace] + * @since 13.0.0 + */ + public function getUsedSpaceForUsers(array $users); + + /** + * Clear all entries from the in-memory cache + * + * @since 20.0.0 + */ + public function clear(): void; + + /** + * Get all cached mounts for a user + * + * @param IUser $user + * @param string $path + * @return ICachedMountInfo + * @throws NotFoundException + * @since 24.0.0 + */ + public function getMountForPath(IUser $user, string $path): ICachedMountInfo; + + /** + * Get all cached mounts for a user inside a path + * + * @param IUser $user + * @param string $path + * @return ICachedMountInfo[] + * @throws NotFoundException + * @since 24.0.0 + */ + public function getMountsInPath(IUser $user, string $path): array; +} |