From ef5e014d3a9f406873acdd459d27bd10b299955d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Nov 2025 17:34:38 +0100 Subject: [PATCH] feat: add command to list mounts for user Signed-off-by: Robin Appelman --- apps/files/appinfo/info.xml | 1 + .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/files/lib/Command/Mount/ListMounts.php | 80 +++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 apps/files/lib/Command/Mount/ListMounts.php diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index fbccac74c36..1fdde56e09f 100644 --- a/apps/files/appinfo/info.xml +++ b/apps/files/appinfo/info.xml @@ -48,6 +48,7 @@ OCA\Files\Command\Move OCA\Files\Command\SanitizeFilenames OCA\Files\Command\Mount\Refresh + OCA\Files\Command\Mount\ListMounts OCA\Files\Command\Object\Delete OCA\Files\Command\Object\Get OCA\Files\Command\Object\Put diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index f051075172a..90b5f1d4a2c 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -33,6 +33,7 @@ return array( 'OCA\\Files\\Command\\Delete' => $baseDir . '/../lib/Command/Delete.php', 'OCA\\Files\\Command\\DeleteOrphanedFiles' => $baseDir . '/../lib/Command/DeleteOrphanedFiles.php', 'OCA\\Files\\Command\\Get' => $baseDir . '/../lib/Command/Get.php', + 'OCA\\Files\\Command\\Mount\\ListMounts' => $baseDir . '/../lib/Command/Mount/ListMounts.php', 'OCA\\Files\\Command\\Mount\\Refresh' => $baseDir . '/../lib/Command/Mount/Refresh.php', 'OCA\\Files\\Command\\Move' => $baseDir . '/../lib/Command/Move.php', 'OCA\\Files\\Command\\Object\\Delete' => $baseDir . '/../lib/Command/Object/Delete.php', diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index 1c449c99237..c1939522c78 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -48,6 +48,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Command\\Delete' => __DIR__ . '/..' . '/../lib/Command/Delete.php', 'OCA\\Files\\Command\\DeleteOrphanedFiles' => __DIR__ . '/..' . '/../lib/Command/DeleteOrphanedFiles.php', 'OCA\\Files\\Command\\Get' => __DIR__ . '/..' . '/../lib/Command/Get.php', + 'OCA\\Files\\Command\\Mount\\ListMounts' => __DIR__ . '/..' . '/../lib/Command/Mount/ListMounts.php', 'OCA\\Files\\Command\\Mount\\Refresh' => __DIR__ . '/..' . '/../lib/Command/Mount/Refresh.php', 'OCA\\Files\\Command\\Move' => __DIR__ . '/..' . '/../lib/Command/Move.php', 'OCA\\Files\\Command\\Object\\Delete' => __DIR__ . '/..' . '/../lib/Command/Object/Delete.php', diff --git a/apps/files/lib/Command/Mount/ListMounts.php b/apps/files/lib/Command/Mount/ListMounts.php new file mode 100644 index 00000000000..b4abeac5ab8 --- /dev/null +++ b/apps/files/lib/Command/Mount/ListMounts.php @@ -0,0 +1,80 @@ +setName('files:mount:list') + ->setDescription('List of mounts for a user') + ->addArgument('user', InputArgument::REQUIRED, 'User to list mounts for'); + } + + public function execute(InputInterface $input, OutputInterface $output): int { + $userId = $input->getArgument('user'); + $user = $this->userManager->get($userId); + if (!$user) { + $output->writeln("User $userId not found"); + return 1; + } + + $mounts = $this->mountProviderCollection->getMountsForUser($user); + $mounts[] = $this->mountProviderCollection->getHomeMountForUser($user); + /** @var array $cachedByMountpoint */ + $mountsByMountpoint = array_combine(array_map(fn (IMountPoint $mount) => $mount->getMountPoint(), $mounts), $mounts); + usort($mounts, fn (IMountPoint $a, IMountPoint $b) => $a->getMountPoint() <=> $b->getMountPoint()); + + $cachedMounts = $this->userMountCache->getMountsForUser($user); + usort($cachedMounts, fn (ICachedMountInfo $a, ICachedMountInfo $b) => $a->getMountPoint() <=> $b->getMountPoint()); + /** @var array $cachedByMountpoint */ + $cachedByMountpoint = array_combine(array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts), $cachedMounts); + + foreach ($mounts as $mount) { + $output->writeln('' . $mount->getMountPoint() . ': ' . $mount->getStorageId()); + if (isset($cachedByMountpoint[$mount->getMountPoint()])) { + $cached = $cachedByMountpoint[$mount->getMountPoint()]; + $output->writeln("\t- provider: " . $cached->getMountProvider()); + $output->writeln("\t- storage id: " . $cached->getStorageId()); + $output->writeln("\t- root id: " . $cached->getRootId()); + } else { + $output->writeln("\tnot registered"); + } + } + foreach ($cachedMounts as $cachedMount) { + if (!isset($mountsByMountpoint[$cachedMount->getMountPoint()])) { + $output->writeln('' . $cachedMount->getMountPoint() . ':'); + $output->writeln("\tregistered but no longer provided"); + $output->writeln("\t- provider: " . $cachedMount->getMountProvider()); + $output->writeln("\t- storage id: " . $cachedMount->getStorageId()); + $output->writeln("\t- root id: " . $cachedMount->getRootId()); + } + } + + return 0; + } + +}