88
99namespace OCA \Encryption \Command ;
1010
11+ use OC \Files \SetupManager ;
1112use OC \Files \Storage \Wrapper \Encryption ;
1213use OC \Files \View ;
1314use OC \ServerNotAvailableException ;
1415use OCA \Encryption \Util ;
1516use OCP \Encryption \Exceptions \InvalidHeaderException ;
16- use OCP \Files \IRootFolder ;
1717use OCP \HintException ;
1818use OCP \IConfig ;
1919use OCP \IUser ;
@@ -29,12 +29,12 @@ class FixEncryptedVersion extends Command {
2929 private bool $ supportLegacy = false ;
3030
3131 public function __construct (
32- private IConfig $ config ,
33- private LoggerInterface $ logger ,
34- private IRootFolder $ rootFolder ,
35- private IUserManager $ userManager ,
36- private Util $ util ,
37- private View $ view ,
32+ private readonly IConfig $ config ,
33+ private readonly LoggerInterface $ logger ,
34+ private readonly IUserManager $ userManager ,
35+ private readonly Util $ util ,
36+ private readonly View $ view ,
37+ private readonly SetupManager $ setupManager ,
3838 ) {
3939 parent ::__construct ();
4040 }
@@ -91,45 +91,43 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9191 return self ::FAILURE ;
9292 }
9393
94- if ($ this ->userManager ->get ($ user ) === null ) {
94+ $ user = $ this ->userManager ->get ($ user );
95+ if ($ user === null ) {
9596 $ output ->writeln ("<error>User id $ user does not exist. Please provide a valid user id</error> " );
9697 return self ::FAILURE ;
9798 }
9899
99- return $ this ->runForUser ($ user , $ pathOption , $ output );
100+ return $ this ->runForUser ($ user , $ pathOption , $ output ) ? self :: SUCCESS : self :: FAILURE ;
100101 }
101102
102- $ result = 0 ;
103- $ this ->userManager ->callForSeenUsers (function (IUser $ user ) use ($ pathOption , $ output , &$ result ) {
103+ foreach ($ this ->userManager ->getSeenUsers () as $ user ) {
104104 $ output ->writeln ('Processing files for ' . $ user ->getUID ());
105- $ result = $ this ->runForUser ($ user ->getUID (), $ pathOption , $ output );
106- return $ result === 0 ;
107- });
108- return $ result ;
105+ if (!$ this ->runForUser ($ user , $ pathOption , $ output )) {
106+ return self ::FAILURE ;
107+ }
108+ }
109+ return self ::SUCCESS ;
109110 }
110111
111- private function runForUser (string $ user , string $ pathOption , OutputInterface $ output ): int {
112- $ pathToWalk = " / $ user/files " ;
112+ private function runForUser (IUser $ user , string $ pathOption , OutputInterface $ output ): bool {
113+ $ pathToWalk = ' / ' . $ user-> getUID () . ' /files ' ;
113114 if ($ pathOption !== '' ) {
114115 $ pathToWalk = "$ pathToWalk/ $ pathOption " ;
115116 }
116117 return $ this ->walkPathOfUser ($ user , $ pathToWalk , $ output );
117118 }
118119
119- /**
120- * @return int 0 for success, 1 for error
121- */
122- private function walkPathOfUser (string $ user , string $ path , OutputInterface $ output ): int {
123- $ this ->setupUserFs ($ user );
120+ private function walkPathOfUser (IUser $ user , string $ path , OutputInterface $ output ): bool {
121+ $ this ->setupUserFileSystem ($ user );
124122 if (!$ this ->view ->file_exists ($ path )) {
125123 $ output ->writeln ("<error>Path \"$ path \" does not exist. Please provide a valid path.</error> " );
126- return self :: FAILURE ;
124+ return false ;
127125 }
128126
129127 if ($ this ->view ->is_file ($ path )) {
130128 $ output ->writeln ("Verifying the content of file \"$ path \"" );
131129 $ this ->verifyFileContent ($ path , $ output );
132- return self :: SUCCESS ;
130+ return true ;
133131 }
134132 $ directories = [];
135133 $ directories [] = $ path ;
@@ -145,7 +143,7 @@ private function walkPathOfUser(string $user, string $path, OutputInterface $out
145143 }
146144 }
147145 }
148- return self :: SUCCESS ;
146+ return true ;
149147 }
150148
151149 /**
@@ -309,8 +307,8 @@ private function correctEncryptedVersion(string $path, OutputInterface $output,
309307 /**
310308 * Setup user file system
311309 */
312- private function setupUserFs ( string $ uid ): void {
313- \OC_Util:: tearDownFS ();
314- \OC_Util:: setupFS ( $ uid );
310+ private function setupUserFileSystem ( IUser $ user ): void {
311+ $ this -> setupManager -> tearDown ();
312+ $ this -> setupManager -> setupForUser ( $ user );
315313 }
316314}
0 commit comments