88
99namespace OCA \Files \Command \Mount ;
1010
11- use OC \Core \Command \Base ;
1211use OCP \Files \Config \ICachedMountInfo ;
1312use OCP \Files \Config \IMountProviderCollection ;
1413use OCP \Files \Config \IUserMountCache ;
1514use OCP \Files \Mount \IMountPoint ;
1615use OCP \IUserManager ;
16+ use Symfony \Component \Console \Command \Command ;
1717use Symfony \Component \Console \Input \InputArgument ;
1818use Symfony \Component \Console \Input \InputInterface ;
19- use Symfony \Component \Console \Input \InputOption ;
2019use Symfony \Component \Console \Output \OutputInterface ;
2120
22- class ListMounts extends Base {
21+ class ListMounts extends Command {
2322 public function __construct (
2423 private readonly IUserManager $ userManager ,
2524 private readonly IUserMountCache $ userMountCache ,
@@ -29,81 +28,52 @@ public function __construct(
2928 }
3029
3130 protected function configure (): void {
32- parent ::configure ();
3331 $ this
3432 ->setName ('files:mount:list ' )
3533 ->setDescription ('List of mounts for a user ' )
36- ->addArgument ('user ' , InputArgument::REQUIRED , 'User to list mounts for ' )
37- ->addOption ('cached-only ' , null , InputOption::VALUE_NONE , 'Only return cached mounts, prevents filesystem setup ' );
34+ ->addArgument ('user ' , InputArgument::REQUIRED , 'User to list mounts for ' );
3835 }
3936
4037 public function execute (InputInterface $ input , OutputInterface $ output ): int {
4138 $ userId = $ input ->getArgument ('user ' );
42- $ cachedOnly = $ input ->getOption ('cached-only ' );
4339 $ user = $ this ->userManager ->get ($ userId );
4440 if (!$ user ) {
4541 $ output ->writeln ("<error>User $ userId not found</error> " );
4642 return 1 ;
4743 }
4844
49- if ($ cachedOnly ) {
50- $ mounts = [];
51- } else {
52- $ mounts = $ this ->mountProviderCollection ->getMountsForUser ($ user );
53- $ mounts [] = $ this ->mountProviderCollection ->getHomeMountForUser ($ user );
54- }
55- /** @var array<string, IMountPoint> $cachedByMountPoint */
56- $ mountsByMountPoint = array_combine (array_map (fn (IMountPoint $ mount ) => $ mount ->getMountPoint (), $ mounts ), $ mounts );
45+ $ mounts = $ this ->mountProviderCollection ->getMountsForUser ($ user );
46+ $ mounts [] = $ this ->mountProviderCollection ->getHomeMountForUser ($ user );
47+ /** @var array<string, IMountPoint> $cachedByMountpoint */
48+ $ mountsByMountpoint = array_combine (array_map (fn (IMountPoint $ mount ) => $ mount ->getMountPoint (), $ mounts ), $ mounts );
5749 usort ($ mounts , fn (IMountPoint $ a , IMountPoint $ b ) => $ a ->getMountPoint () <=> $ b ->getMountPoint ());
5850
5951 $ cachedMounts = $ this ->userMountCache ->getMountsForUser ($ user );
6052 usort ($ cachedMounts , fn (ICachedMountInfo $ a , ICachedMountInfo $ b ) => $ a ->getMountPoint () <=> $ b ->getMountPoint ());
6153 /** @var array<string, ICachedMountInfo> $cachedByMountpoint */
62- $ cachedByMountPoint = array_combine (array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts ), $ cachedMounts );
63-
64- $ format = $ input ->getOption ('output ' );
54+ $ cachedByMountpoint = array_combine (array_map (fn (ICachedMountInfo $ mount ) => $ mount ->getMountPoint (), $ cachedMounts ), $ cachedMounts );
6555
66- if ($ format === self ::OUTPUT_FORMAT_PLAIN ) {
67- foreach ($ mounts as $ mount ) {
68- $ output ->writeln ('<info> ' . $ mount ->getMountPoint () . '</info>: ' . $ mount ->getStorageId ());
69- if (isset ($ cachedByMountPoint [$ mount ->getMountPoint ()])) {
70- $ cached = $ cachedByMountPoint [$ mount ->getMountPoint ()];
71- $ output ->writeln ("\t- provider: " . $ cached ->getMountProvider ());
72- $ output ->writeln ("\t- storage id: " . $ cached ->getStorageId ());
73- $ output ->writeln ("\t- root id: " . $ cached ->getRootId ());
74- } else {
75- $ output ->writeln ("\t<error>not registered</error> " );
76- }
56+ foreach ($ mounts as $ mount ) {
57+ $ output ->writeln ('<info> ' . $ mount ->getMountPoint () . '</info>: ' . $ mount ->getStorageId ());
58+ if (isset ($ cachedByMountpoint [$ mount ->getMountPoint ()])) {
59+ $ cached = $ cachedByMountpoint [$ mount ->getMountPoint ()];
60+ $ output ->writeln ("\t- provider: " . $ cached ->getMountProvider ());
61+ $ output ->writeln ("\t- storage id: " . $ cached ->getStorageId ());
62+ $ output ->writeln ("\t- root id: " . $ cached ->getRootId ());
63+ } else {
64+ $ output ->writeln ("\t<error>not registered</error> " );
7765 }
78- foreach ($ cachedMounts as $ cachedMount ) {
79- if ($ cachedOnly || !isset ($ mountsByMountPoint [$ cachedMount ->getMountPoint ()])) {
80- $ output ->writeln ('<info> ' . $ cachedMount ->getMountPoint () . '</info>: ' );
81- if (!$ cachedOnly ) {
82- $ output ->writeln ("\t<error>registered but no longer provided</error> " );
83- }
84- $ output ->writeln ("\t- provider: " . $ cachedMount ->getMountProvider ());
85- $ output ->writeln ("\t- storage id: " . $ cachedMount ->getStorageId ());
86- $ output ->writeln ("\t- root id: " . $ cachedMount ->getRootId ());
87- }
66+ }
67+ foreach ($ cachedMounts as $ cachedMount ) {
68+ if (!isset ($ mountsByMountpoint [$ cachedMount ->getMountPoint ()])) {
69+ $ output ->writeln ('<info> ' . $ cachedMount ->getMountPoint () . '</info>: ' );
70+ $ output ->writeln ("\t<error>registered but no longer provided</error> " );
71+ $ output ->writeln ("\t- provider: " . $ cachedMount ->getMountProvider ());
72+ $ output ->writeln ("\t- storage id: " . $ cachedMount ->getStorageId ());
73+ $ output ->writeln ("\t- root id: " . $ cachedMount ->getRootId ());
8874 }
89- } else {
90- $ cached = array_map (fn (ICachedMountInfo $ cachedMountInfo ) => [
91- 'mountpoint ' => $ cachedMountInfo ->getMountPoint (),
92- 'provider ' => $ cachedMountInfo ->getMountProvider (),
93- 'storage_id ' => $ cachedMountInfo ->getStorageId (),
94- 'root_id ' => $ cachedMountInfo ->getRootId (),
95- ], $ cachedMounts );
96- $ provided = array_map (fn (IMountPoint $ cachedMountInfo ) => [
97- 'mountpoint ' => $ cachedMountInfo ->getMountPoint (),
98- 'provider ' => $ cachedMountInfo ->getMountProvider (),
99- 'storage_id ' => $ cachedMountInfo ->getStorageId (),
100- 'root_id ' => $ cachedMountInfo ->getStorageRootId (),
101- ], $ mounts );
102- $ this ->writeArrayInOutputFormat ($ input , $ output , array_filter ([
103- 'cached ' => $ cached ,
104- 'provided ' => $ cachedOnly ? null : $ provided ,
105- ]));
10675 }
76+
10777 return 0 ;
10878 }
10979
0 commit comments