Commit cc5aa2b6 cc5aa2b649dda028e0759376e4c855af35e8b4c5 by Sergey Poznyakoff

Fixed scanning of folders and producing the output.

1 parent c9e3e0a5
Showing 1 changed file with 39 additions and 40 deletions
...@@ -254,20 +254,26 @@ _scan (const char *name, int depth) ...@@ -254,20 +254,26 @@ _scan (const char *name, int depth)
254 info.name = strdup (name); 254 info.name = strdup (name);
255 while ((entry = readdir (dir))) 255 while ((entry = readdir (dir)))
256 { 256 {
257 switch (entry->d_name[0]) 257 if (entry->d_name[0] == '.')
258 { 258 {
259 case '.':
260 if (strcmp (entry->d_name, mh_seq_name) == 0) 259 if (strcmp (entry->d_name, mh_seq_name) == 0)
261 read_seq_file (&info, name, entry->d_name); 260 read_seq_file (&info, name, entry->d_name);
262 break; 261 }
263 262 else if (entry->d_name[0] != ',')
264 case ',': 263 {
265 continue; 264 asprintf (&p, "%s/%s", name, entry->d_name);
266 265 if (stat (p, &st) < 0)
267 case '0':case '1':case '2':case '3':case '4': 266 mh_error ("can't stat %s: %s", p, strerror (errno));
268 case '5':case '6':case '7':case '8':case '9': 267 else if (S_ISDIR (st.st_mode))
269 uid = strtoul (entry->d_name, &p, 10); 268 {
270 if (*p) 269 info.others++;
270 _scan (p, depth+1);
271 }
272 else
273 {
274 char *endp;
275 uid = strtoul (entry->d_name, &endp, 10);
276 if (*endp)
271 info.others++; 277 info.others++;
272 else 278 else
273 { 279 {
...@@ -277,27 +283,19 @@ _scan (const char *name, int depth) ...@@ -277,27 +283,19 @@ _scan (const char *name, int depth)
277 if (uid > info.max) 283 if (uid > info.max)
278 info.max = uid; 284 info.max = uid;
279 } 285 }
280 break;
281
282 default:
283 asprintf (&p, "%s/%s", name, entry->d_name);
284 if (stat (p, &st) < 0)
285 {
286 mh_error ("can't stat %s: %s", p, strerror (errno));
287 info.others++;
288 } 286 }
289 else if (S_ISDIR (st.st_mode))
290 {
291 _scan (p, depth+1);
292 } 287 }
293 else
294 /* Invalid entry. */
295 info.others++;
296 free (p);
297 } 288 }
298 289
290 if (info.cur)
291 {
292 asprintf (&p, "%s/%lu", name, (unsigned long) info.cur);
293 if (stat (p, &st) < 0 || !S_ISREG (st.st_mode))
294 info.cur = 0;
295 free (p);
299 } 296 }
300 closedir (dir); 297 closedir (dir);
298 if (depth > 0)
301 install_folder_info (name, &info); 299 install_folder_info (name, &info);
302 } 300 }
303 301
...@@ -309,24 +307,31 @@ print_all () ...@@ -309,24 +307,31 @@ print_all ()
309 for (info = folder_info; info < end; info++) 307 for (info = folder_info; info < end; info++)
310 { 308 {
311 int len = strlen (info->name); 309 int len = strlen (info->name);
310 if (len < 22)
311 printf ("%22.22s", info->name);
312 else
312 printf ("%s", info->name); 313 printf ("%s", info->name);
314
313 if (strcmp (info->name, current_folder) == 0) 315 if (strcmp (info->name, current_folder) == 0)
314 {
315 printf ("+"); 316 printf ("+");
316 len++; 317 else
317 } 318 printf (" ");
318
319 for (; len < 20; len++)
320 putchar (' ');
321 319
322 if (info->message_count) 320 if (info->message_count)
323 { 321 {
324 printf (" has %4lu messages (%4lu-%4lu)", 322 printf (info->message_count == 1 ?
323 " has %4lu message (%4lu-%4lu)" :
324 " has %4lu messages (%4lu-%4lu)",
325 (unsigned long) info->message_count, 325 (unsigned long) info->message_count,
326 (unsigned long) info->min, 326 (unsigned long) info->min,
327 (unsigned long) info->max); 327 (unsigned long) info->max);
328 if (info->cur) 328 if (info->cur)
329 printf ("; cur=%4lu", (unsigned long) info->cur); 329 printf ("; cur=%4lu", (unsigned long) info->cur);
330 }
331 else
332 {
333 printf (" has no messages");
334 }
330 335
331 if (info->others) 336 if (info->others)
332 { 337 {
...@@ -338,11 +343,6 @@ print_all () ...@@ -338,11 +343,6 @@ print_all ()
338 } 343 }
339 printf (".\n"); 344 printf (".\n");
340 } 345 }
341 else
342 {
343 printf (" has no messages.\n");
344 }
345 }
346 } 346 }
347 347
348 static void 348 static void
...@@ -374,7 +374,6 @@ action_print () ...@@ -374,7 +374,6 @@ action_print ()
374 if (show_all) 374 if (show_all)
375 { 375 {
376 _scan (mu_path_folder_dir, 0); 376 _scan (mu_path_folder_dir, 0);
377 folder_info_count--; /* do not count folder directory */
378 } 377 }
379 else 378 else
380 { 379 {
...@@ -398,7 +397,7 @@ action_print () ...@@ -398,7 +397,7 @@ action_print ()
398 print_all (); 397 print_all ();
399 398
400 if (print_total) 399 if (print_total)
401 printf ("%24.24s=%4lu messages in %4lu folders\n", 400 printf ("\n%24.24s=%4lu messages in %4lu folders\n",
402 "TOTAL", 401 "TOTAL",
403 (unsigned long) message_count, 402 (unsigned long) message_count,
404 (unsigned long) folder_info_count); 403 (unsigned long) folder_info_count);
......