X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Ffolder.c;h=a94f1315ff94a83c5e9fe702280f2ced870f87f4;hb=1ae9fa8a84998e44e0234543162e257815d7e972;hp=a0821c275bb6a03ba92cd841f7c4f6cd3c0315df;hpb=ef8679ef6af0ba01d8dc43df577c5962037f13bd;p=mmh diff --git a/uip/folder.c b/uip/folder.c index a0821c2..a94f131 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -365,6 +365,9 @@ main (int argc, char **argv) /* * If no folder is given, do them all */ + /* change directory to base of nmh directory for dodir */ + if (chdir (nmhdir) == NOTOK) + adios (nmhdir, "unable to change directory to"); if (!argfolder) { if (msg) admonish (NULL, "no folder given for message %s", msg); @@ -422,10 +425,6 @@ dodir (char *dir) start = foldp; - /* change directory to base of nmh directory */ - if (chdir (nmhdir) == NOTOK) - adios (nmhdir, "unable to change directory to"); - addir (dir); for (i = start; i < foldp; i++) { @@ -441,7 +440,6 @@ static int get_folder_info (char *fold, char *msg) { int i, retval = 1; - char *mailfile; struct msgs *mp = NULL; i = total_folders++; @@ -463,42 +461,36 @@ get_folder_info (char *fold, char *msg) fi[i].others = 0; fi[i].error = 0; - mailfile = m_maildir (fold); - - if (!chdir (mailfile)) { - if ((ftotal > 0) || !fshort || msg || fpack) { - /* - * create message structure and get folder info - */ - if (!(mp = folder_read (fold))) { - admonish (NULL, "unable to read folder %s", fold); - return 0; - } - - /* set the current message */ - if (msg && !sfold (mp, msg)) - retval = 0; + if ((ftotal > 0) || !fshort || msg || fpack) { + /* + * create message structure and get folder info + */ + if (!(mp = folder_read (fold))) { + admonish (NULL, "unable to read folder %s", fold); + return 0; + } - if (fpack) { - if (folder_pack (&mp, fverb) == -1) - done (1); - seq_save (mp); /* synchronize the sequences */ - context_save (); /* save the context file */ - } + /* set the current message */ + if (msg && !sfold (mp, msg)) + retval = 0; - /* record info for this folder */ - if ((ftotal > 0) || !fshort) { - fi[i].nummsg = mp->nummsg; - fi[i].curmsg = mp->curmsg; - fi[i].lowmsg = mp->lowmsg; - fi[i].hghmsg = mp->hghmsg; - fi[i].others = other_files (mp); - } + if (fpack) { + if (folder_pack (&mp, fverb) == -1) + done (1); + seq_save (mp); /* synchronize the sequences */ + context_save (); /* save the context file */ + } - folder_free (mp); /* free folder/message structure */ + /* record info for this folder */ + if ((ftotal > 0) || !fshort) { + fi[i].nummsg = mp->nummsg; + fi[i].curmsg = mp->curmsg; + fi[i].lowmsg = mp->lowmsg; + fi[i].hghmsg = mp->hghmsg; + fi[i].others = other_files (mp); } - } else { - fi[i].error = 1; + + folder_free (mp); /* free folder/message structure */ } if (frecurse && (fshort || fi[i].others) && (fi[i].error == 0)) @@ -665,16 +657,12 @@ sfold (struct msgs *mp, char *msg) static void addir (char *name) { - int nlink; char *prefix, *child; struct stat st; struct dirent *dp; DIR * dd; + int child_is_folder; - /* short-cut to see if directory has any sub-directories */ - if (stat (name, &st) != -1 && st.st_nlink == 2) - return; - if (!(dd = opendir (name))) { admonish (name, "unable to read directory "); return; @@ -686,25 +674,27 @@ addir (char *name) prefix = concat (name, "/", (void *)NULL); } - /* - * Keep track of the number of directories we've seen - * so we can quit stat'ing early, if we've seen them all. - */ - nlink = st.st_nlink; - - while (nlink && (dp = readdir (dd))) { + while ((dp = readdir (dd))) { + /* If the system supports it, try to skip processing of children we + * know are not directories or symlinks. */ + child_is_folder = -1; +#if defined(HAVE_STRUCT_DIRENT_D_TYPE) + if (dp->d_type == DT_DIR) { + child_is_folder = 1; + } else if (dp->d_type != DT_LNK && dp->d_type != DT_UNKNOWN) { + continue; + } +#endif if (!strcmp (dp->d_name, ".") || !strcmp (dp->d_name, "..")) { - nlink--; continue; } child = concat (prefix, dp->d_name, (void *)NULL); - if (stat (child, &st) != -1 && S_ISDIR(st.st_mode)) { - /* - * Check if this was really a symbolic link pointing at - * a directory. If not, then decrement link count. - */ - if (lstat (child, &st) == -1) - nlink--; + /* If we have no d_type or d_type is DT_LNK or DT_UNKNOWN, stat the + * child to see what it is. */ + if (child_is_folder == -1) { + child_is_folder = (stat (child, &st) != -1 && S_ISDIR(st.st_mode)); + } + if (child_is_folder) { /* addfold saves child in the list, don't free it */ addfold (child); } else {