X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;h=50597b75c07e3419c8bccdbc1ab35b2143a1c2e4;hp=e011788da590a74433a526c5fe727e604be7db3e;hb=54aef071590cb23f61da943daa29080cf7446696;hpb=0082a55785a5ae64da22fe72af6c0ae928f13c03 diff --git a/notmuch-new.c b/notmuch-new.c index e011788d..50597b75 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -234,6 +234,12 @@ _entries_resemble_maildir (const char *path, struct dirent **entries, int count) return 0; } +static notmuch_bool_t +_special_directory (const char *entry) +{ + return strcmp (entry, ".") == 0 || strcmp (entry, "..") == 0; +} + /* Test if the file/directory is to be ignored. */ static notmuch_bool_t @@ -443,12 +449,13 @@ add_files (notmuch_database_t *notmuch, /* Pass 1: Recurse into all sub-directories. */ is_maildir = _entries_resemble_maildir (path, fs_entries, num_fs_entries); - for (i = 0; i < num_fs_entries; i++) { - if (interrupted) - break; - + for (i = 0; i < num_fs_entries && ! interrupted; i++) { entry = fs_entries[i]; + /* Ignore special directories to avoid infinite recursion. */ + if (_special_directory (entry->d_name)) + continue; + /* Ignore any files/directories the user has configured to * ignore. We do this before dirent_type both for performance * and because we don't care if dirent_type fails on entries @@ -474,13 +481,10 @@ add_files (notmuch_database_t *notmuch, continue; } - /* Ignore special directories to avoid infinite recursion. - * Also ignore the .notmuch directory and any "tmp" directory + /* Ignore the .notmuch directory and any "tmp" directory * that appears within a maildir. */ - if (strcmp (entry->d_name, ".") == 0 || - strcmp (entry->d_name, "..") == 0 || - (is_maildir && strcmp (entry->d_name, "tmp") == 0) || + if ((is_maildir && strcmp (entry->d_name, "tmp") == 0) || strcmp (entry->d_name, ".notmuch") == 0) continue; @@ -514,13 +518,13 @@ add_files (notmuch_database_t *notmuch, } /* Pass 2: Scan for new files, removed files, and removed directories. */ - for (i = 0; i < num_fs_entries; i++) - { - if (interrupted) - break; - + for (i = 0; i < num_fs_entries && ! interrupted; i++) { entry = fs_entries[i]; + /* Ignore special directories early. */ + if (_special_directory (entry->d_name)) + continue; + /* Ignore files & directories user has configured to be ignored */ if (_entry_in_ignore_list (entry->d_name, state)) { if (state->debug) @@ -745,8 +749,7 @@ count_files (const char *path, int *count, add_files_state_t *state) /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory. */ - if (strcmp (entry->d_name, ".") == 0 || - strcmp (entry->d_name, "..") == 0 || + if (_special_directory (entry->d_name) || strcmp (entry->d_name, ".notmuch") == 0) continue; @@ -956,12 +959,12 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) notmuch_status_t status; notmuch_opt_desc_t options[] = { - { NOTMUCH_OPT_BOOLEAN, &quiet, "quiet", 'q', 0 }, - { NOTMUCH_OPT_BOOLEAN, &verbose, "verbose", 'v', 0 }, - { NOTMUCH_OPT_BOOLEAN, &add_files_state.debug, "debug", 'd', 0 }, - { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 }, - { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, - { 0, 0, 0, 0, 0 } + { .opt_bool = &quiet, .name = "quiet" }, + { .opt_bool = &verbose, .name = "verbose" }, + { .opt_bool = &add_files_state.debug, .name = "debug" }, + { .opt_bool = &no_hooks, .name = "no-hooks" }, + { .opt_inherit = notmuch_shared_options }, + { } }; opt_index = parse_arguments (argc, argv, options, 1);