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)
info.name = strdup (name);
while ((entry = readdir (dir)))
{
switch (entry->d_name[0])
if (entry->d_name[0] == '.')
{
case '.':
if (strcmp (entry->d_name, mh_seq_name) == 0)
read_seq_file (&info, name, entry->d_name);
break;
case ',':
continue;
case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':
uid = strtoul (entry->d_name, &p, 10);
if (*p)
}
else if (entry->d_name[0] != ',')
{
asprintf (&p, "%s/%s", name, entry->d_name);
if (stat (p, &st) < 0)
mh_error ("can't stat %s: %s", p, strerror (errno));
else if (S_ISDIR (st.st_mode))
{
info.others++;
_scan (p, depth+1);
}
else
{
char *endp;
uid = strtoul (entry->d_name, &endp, 10);
if (*endp)
info.others++;
else
{
......@@ -277,27 +283,19 @@ _scan (const char *name, int depth)
if (uid > info.max)
info.max = uid;
}
break;
default:
asprintf (&p, "%s/%s", name, entry->d_name);
if (stat (p, &st) < 0)
{
mh_error ("can't stat %s: %s", p, strerror (errno));
info.others++;
}
else if (S_ISDIR (st.st_mode))
{
_scan (p, depth+1);
}
else
/* Invalid entry. */
info.others++;
free (p);
}
if (info.cur)
{
asprintf (&p, "%s/%lu", name, (unsigned long) info.cur);
if (stat (p, &st) < 0 || !S_ISREG (st.st_mode))
info.cur = 0;
free (p);
}
closedir (dir);
if (depth > 0)
install_folder_info (name, &info);
}
......@@ -309,24 +307,31 @@ print_all ()
for (info = folder_info; info < end; info++)
{
int len = strlen (info->name);
if (len < 22)
printf ("%22.22s", info->name);
else
printf ("%s", info->name);
if (strcmp (info->name, current_folder) == 0)
{
printf ("+");
len++;
}
for (; len < 20; len++)
putchar (' ');
else
printf (" ");
if (info->message_count)
{
printf (" has %4lu messages (%4lu-%4lu)",
printf (info->message_count == 1 ?
" has %4lu message (%4lu-%4lu)" :
" has %4lu messages (%4lu-%4lu)",
(unsigned long) info->message_count,
(unsigned long) info->min,
(unsigned long) info->max);
if (info->cur)
printf ("; cur=%4lu", (unsigned long) info->cur);
}
else
{
printf (" has no messages");
}
if (info->others)
{
......@@ -338,11 +343,6 @@ print_all ()
}
printf (".\n");
}
else
{
printf (" has no messages.\n");
}
}
}
static void
......@@ -374,7 +374,6 @@ action_print ()
if (show_all)
{
_scan (mu_path_folder_dir, 0);
folder_info_count--; /* do not count folder directory */
}
else
{
......@@ -398,7 +397,7 @@ action_print ()
print_all ();
if (print_total)
printf ("%24.24s=%4lu messages in %4lu folders\n",
printf ("\n%24.24s=%4lu messages in %4lu folders\n",
"TOTAL",
(unsigned long) message_count,
(unsigned long) folder_info_count);
......