X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;ds=sidebyside;f=notmuch-new.c;h=f6d9c3a4508f52cbb2da594a030acee8acdb06b2;hb=f849b371cc78fac73d9a8e0467bc0e6232ced18b;hp=7f3b3b081c2846b7249e9c83b411d043515b1cec;hpb=65ebd34329e31a9a8a6f4a2d1e255ef273b0678e;p=notmuch diff --git a/notmuch-new.c b/notmuch-new.c index 7f3b3b08..f6d9c3a4 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -702,10 +702,9 @@ count_files (const char *path, int *count, add_files_state_t *state) { struct dirent *entry = NULL; char *next; - struct stat st; struct dirent **fs_entries = NULL; int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode); - int i = 0; + int entry_type, i; if (num_fs_entries == -1) { fprintf (stderr, "Warning: failed to open directory %s: %s\n", @@ -713,11 +712,8 @@ count_files (const char *path, int *count, add_files_state_t *state) goto DONE; } - while (!interrupted) { - if (i == num_fs_entries) - break; - - entry = fs_entries[i++]; + for (i = 0; i < num_fs_entries && ! interrupted; i++) { + entry = fs_entries[i]; /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory and files/directories @@ -742,15 +738,14 @@ count_files (const char *path, int *count, add_files_state_t *state) continue; } - stat (next, &st); - - if (S_ISREG (st.st_mode)) { + entry_type = dirent_type (path, entry); + if (entry_type == S_IFREG) { *count = *count + 1; if (*count % 1000 == 0) { printf ("Found %d files so far.\r", *count); fflush (stdout); } - } else if (S_ISDIR (st.st_mode)) { + } else if (entry_type == S_IFDIR) { count_files (next, count, state); }