@@ -93,15 +93,22 @@ protected function configure() {
9393
9494 protected function scanFiles ($ user , $ path , $ verbose , OutputInterface $ output ) {
9595 $ scanner = new \OC \Files \Utils \Scanner ($ user , \OC ::$ server ->getDatabaseConnection (), \OC ::$ server ->getLogger ());
96+ # check on each file/folder if there was a user interrupt (crtl-c) and throw an exeption
9697 # printout and count
9798 if ($ verbose ) {
9899 $ scanner ->listen ('\OC\Files\Utils\Scanner ' , 'scanFile ' , function ($ path ) use ($ output ) {
99- $ output ->writeln ("Scanning file <info>$ path</info> " );
100+ $ output ->writeln ("\t File <info>$ path</info> " );
100101 $ this ->filesCounter += 1 ;
102+ if ($ this ->hasBeenInterrupted ()) {
103+ throw new \Exception ('crtl-c ' );
104+ }
101105 });
102106 $ scanner ->listen ('\OC\Files\Utils\Scanner ' , 'scanFolder ' , function ($ path ) use ($ output ) {
103- $ output ->writeln ("Scanning folder <info>$ path</info> " );
107+ $ output ->writeln ("\t Folder <info>$ path</info> " );
104108 $ this ->foldersCounter += 1 ;
109+ if ($ this ->hasBeenInterrupted ()) {
110+ throw new \Exception ('crtl-c ' );
111+ }
105112 });
106113 $ scanner ->listen ('\OC\Files\Utils\Scanner ' , 'StorageNotAvailable ' , function (StorageNotAvailableException $ e ) use ($ output ) {
107114 $ output ->writeln ("Error while scanning, storage not available ( " . $ e ->getMessage () . ") " );
@@ -110,9 +117,15 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
110117 } else {
111118 $ scanner ->listen ('\OC\Files\Utils\Scanner ' , 'scanFile ' , function ($ path ) use ($ output ) {
112119 $ this ->filesCounter += 1 ;
120+ if ($ this ->hasBeenInterrupted ()) {
121+ throw new \Exception ('crtl-c ' );
122+ }
113123 });
114124 $ scanner ->listen ('\OC\Files\Utils\Scanner ' , 'scanFolder ' , function ($ path ) use ($ output ) {
115125 $ this ->foldersCounter += 1 ;
126+ if ($ this ->hasBeenInterrupted ()) {
127+ throw new \Exception ('crtl-c ' );
128+ }
116129 });
117130 }
118131
@@ -121,6 +134,9 @@ protected function scanFiles($user, $path, $verbose, OutputInterface $output) {
121134 } catch (ForbiddenException $ e ) {
122135 $ output ->writeln ("<error>Home storage for user $ user not writable</error> " );
123136 $ output ->writeln ("Make sure you're running the scan command only as the user the web server runs as " );
137+ } catch (\Exception $ e ) {
138+ # exit the function if crtl-c has been pressed
139+ return ;
124140 }
125141 }
126142
@@ -137,11 +153,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
137153 $ users = $ input ->getArgument ('user_id ' );
138154 }
139155
140- if (count ($ users ) === 0 ) {
141- $ output ->writeln ("<error>Please specify the user id to scan, \"--all \" to scan for all users or \"--path=... \"</error> " );
142- return ;
143- }
144-
145156 # no messaging level option means: no full printout but statistics
146157 # $quiet means no print at all
147158 # $verbose means full printout including statistics
@@ -159,18 +170,38 @@ protected function execute(InputInterface $input, OutputInterface $output) {
159170 $ verbose = false ;
160171 }
161172
173+ # check quantity of users to be process and show it on the command line
174+ $ users_total = count ($ users );
175+ if ($ users_total === 0 ) {
176+ $ output ->writeln ("<error>Please specify the user id to scan, \"--all \" to scan for all users or \"--path=... \"</error> " );
177+ return ;
178+ } else {
179+ if ($ users_total > 1 ) {
180+ $ output ->writeln ("\nScanning files for $ users_total users " );
181+ }
182+ }
183+
162184 $ this ->initTools ();
163185
186+ $ user_count = 0 ;
164187 foreach ($ users as $ user ) {
165188 if (is_object ($ user )) {
166189 $ user = $ user ->getUID ();
167190 }
168191 $ path = $ inputPath ? $ inputPath : '/ ' . $ user ;
192+ $ user_count += 1 ;
169193 if ($ this ->userManager ->userExists ($ user )) {
194+ # add an extra line when verbose is set to optical seperate users
195+ if ($ verbose ) {$ output ->writeln ("" ); }
196+ $ output ->writeln ("Starting scan for user $ user_count out of $ users_total ( $ user) " );
170197 # full: printout data if $verbose was set
171198 $ this ->scanFiles ($ user , $ path , $ verbose , $ output );
172199 } else {
173- $ output ->writeln ("<error>Unknown user $ user</error> " );
200+ $ output ->writeln ("<error>Unknown user $ user_count $ user</error> " );
201+ }
202+ # check on each user if there was a user interrupt (crtl-c) and exit foreach
203+ if ($ this ->hasBeenInterrupted ()) {
204+ break ;
174205 }
175206 }
176207
@@ -182,17 +213,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
182213 }
183214
184215
185- /**
186- * Checks if the command was interrupted by ctrl-c
187- */
188- protected function checkForInterruption ($ output ) {
189- if ($ this ->hasBeenInterrupted ()) {
190- $ this ->presentResults ($ output );
191- exit ;
192- }
193- }
194-
195-
196216 /**
197217 * Initialises some useful tools for the Command
198218 */
@@ -218,6 +238,19 @@ private function cancelOperation() {
218238 }
219239
220240
241+ /**
242+ * @return bool
243+ */
244+ protected function hasBeenInterrupted () {
245+ pcntl_signal_dispatch ();
246+ if ($ this ->interrupted ) {
247+ return true ;
248+ } else {
249+ return false ;
250+ }
251+ }
252+
253+
221254 /**
222255 * Processes PHP errors as exceptions in order to be able to keep track of problems
223256 *
@@ -239,20 +272,6 @@ public function exceptionErrorHandler($severity, $message, $file, $line) {
239272 }
240273
241274
242- /**
243- * @return bool
244- */
245- protected function hasBeenInterrupted () {
246- $ cancelled = false ;
247- pcntl_signal_dispatch ();
248- if ($ this ->interrupted ) {
249- $ cancelled = true ;
250- }
251-
252- return $ cancelled ;
253- }
254-
255-
256275 /**
257276 * @param OutputInterface $output
258277 */
@@ -300,7 +319,8 @@ protected function showSummary($headers, $rows, OutputInterface $output) {
300319 */
301320 protected function formatExecTime () {
302321 list ($ secs , $ tens ) = explode ('. ' , sprintf ("%.1f " , ($ this ->execTime )));
303- $ niceDate = date ('H:i:s ' , $ secs ) . '. ' . $ tens ;
322+ # add the following to $niceDate if you want to have microsecons added: . '.' . $tens;
323+ $ niceDate = date ('H:i:s ' , $ secs );
304324
305325 return $ niceDate ;
306326 }
0 commit comments