setName('files:mount:list') ->setDescription('List of mounts for a user') ->addArgument('user', InputArgument::REQUIRED, 'User to list mounts for') ->addOption('cached-only', null, InputOption::VALUE_NONE, 'Only return cached mounts, prevents filesystem setup'); } #[\Override] public function execute(InputInterface $input, OutputInterface $output): int { $userId = $input->getArgument('user'); $cachedOnly = $input->getOption('cached-only'); $user = $this->userManager->get($userId); if (!$user) { $output->writeln("User $userId not found"); return 1; } if ($cachedOnly) { $mounts = []; } else { $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); $format = $input->getOption('output'); if ($format === self::OUTPUT_FORMAT_PLAIN) { 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 ($cachedOnly || !isset($mountsByMountPoint[$cachedMount->getMountPoint()])) { $output->writeln('' . $cachedMount->getMountPoint() . ':'); if (!$cachedOnly) { $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()); } } } else { $cached = array_map(fn (ICachedMountInfo $cachedMountInfo) => [ 'mountpoint' => $cachedMountInfo->getMountPoint(), 'provider' => $cachedMountInfo->getMountProvider(), 'storage_id' => $cachedMountInfo->getStorageId(), 'root_id' => $cachedMountInfo->getRootId(), ], $cachedMounts); $provided = array_map(fn (IMountPoint $cachedMountInfo) => [ 'mountpoint' => $cachedMountInfo->getMountPoint(), 'provider' => $cachedMountInfo->getMountProvider(), 'storage_id' => $cachedMountInfo->getStorageId(), 'root_id' => $cachedMountInfo->getStorageRootId(), ], $mounts); $this->writeArrayInOutputFormat($input, $output, array_filter([ 'cached' => $cached, 'provided' => $cachedOnly ? null : $provided, ])); } return 0; } }