X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=notmuch-new.c;h=490101d05ae1ffdf1829ef6e2ff1f211f7ed145d;hb=2c4555f1a56602ff1dd55a63699810522ba4d91e;hp=fe280d841c8f50ce2b84ff94c04770b648c32606;hpb=dde214c768a948222786b4c2b5ec404a4ffacc8c;p=notmuch diff --git a/notmuch-new.c b/notmuch-new.c index fe280d84..490101d0 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -141,7 +141,6 @@ is_maildir (struct dirent **entries, int count) static notmuch_status_t add_files_recursive (notmuch_database_t *notmuch, const char *path, - struct stat *st, add_files_state_t *state) { DIR *dir = NULL; @@ -153,8 +152,20 @@ add_files_recursive (notmuch_database_t *notmuch, struct dirent **namelist = NULL; int num_entries; notmuch_directory_t *directory; + struct stat st; - fs_mtime = st->st_mtime; + if (stat (path, &st)) { + fprintf (stderr, "Error reading directory %s: %s\n", + path, strerror (errno)); + return NOTMUCH_STATUS_FILE_ERROR; + } + + if (! S_ISDIR (st.st_mode)) { + fprintf (stderr, "Error: %s is not a directory.\n", path); + return NOTMUCH_STATUS_FILE_ERROR; + } + + fs_mtime = st.st_mtime; directory = notmuch_database_get_directory (notmuch, path); db_mtime = notmuch_directory_get_mtime (directory); @@ -199,25 +210,7 @@ add_files_recursive (notmuch_database_t *notmuch, next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); - if (stat (next, st)) { - int err = errno; - - switch (err) { - case ENOENT: - /* The file was removed between scandir and now... */ - case EPERM: - case EACCES: - /* We can't read this file so don't add it to the cache. */ - continue; - } - - fprintf (stderr, "Error reading %s: %s\n", - next, strerror (errno)); - ret = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } - - if (S_ISREG (st->st_mode)) { + if (entry->d_type == DT_REG) { state->processed_files++; if (state->verbose) { @@ -275,8 +268,8 @@ add_files_recursive (notmuch_database_t *notmuch, do_add_files_print_progress = 0; add_files_print_progress (state); } - } else if (S_ISDIR (st->st_mode)) { - status = add_files_recursive (notmuch, next, st, state); + } else if (entry->d_type == DT_DIR) { + status = add_files_recursive (notmuch, next, state); if (status && ret == NOTMUCH_STATUS_SUCCESS) ret = status; } @@ -312,23 +305,11 @@ add_files (notmuch_database_t *notmuch, const char *path, add_files_state_t *state) { - struct stat st; notmuch_status_t status; struct sigaction action; struct itimerval timerval; notmuch_bool_t timer_is_active = FALSE; - if (stat (path, &st)) { - fprintf (stderr, "Error reading directory %s: %s\n", - path, strerror (errno)); - return NOTMUCH_STATUS_FILE_ERROR; - } - - if (! S_ISDIR (st.st_mode)) { - fprintf (stderr, "Error: %s is not a directory.\n", path); - return NOTMUCH_STATUS_FILE_ERROR; - } - if (state->output_is_a_tty && ! debugger_is_active () && ! state->verbose) { /* Setup our handler for SIGALRM */ memset (&action, 0, sizeof (struct sigaction)); @@ -347,7 +328,7 @@ add_files (notmuch_database_t *notmuch, timer_is_active = TRUE; } - status = add_files_recursive (notmuch, path, &st, state); + status = add_files_recursive (notmuch, path, state); if (timer_is_active) { /* Now stop the timer. */