aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-new.c
diff options
context:
space:
mode:
authorGravatar Jani Nikula <jani@nikula.org>2014-01-19 22:32:24 +0200
committerGravatar David Bremner <david@tethera.net>2014-01-26 09:38:22 -0400
commit0b247cb411fa7530003bad920bd2c85ed46187b5 (patch)
treebd98d83c043a774227b0e0b943db7701c6822bdb /notmuch-new.c
parent65ebd34329e31a9a8a6f4a2d1e255ef273b0678e (diff)
cli: use dirent_type in count_files too
Avoid an extra stat per file, if possible, also when counting the files for initial indexing.
Diffstat (limited to 'notmuch-new.c')
-rw-r--r--notmuch-new.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/notmuch-new.c b/notmuch-new.c
index 7f3b3b08..e6ca8414 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -702,9 +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 entry_type;
int i = 0;
if (num_fs_entries == -1) {
@@ -742,15 +742,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);
}