X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;h=0dd27844d289470b84cbdeba9b375d832277331c;hp=6264628a4b8b01aa2f6267038eac16257db69453;hb=018ca890a3e6ca1cb1068fd789674e475c4a285f;hpb=9794f19017e028b542ed715bef3fd7cf0da5edff diff --git a/notmuch-new.c b/notmuch-new.c index 6264628a..0dd27844 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -20,6 +20,8 @@ #include "notmuch-client.h" +#include + static volatile sig_atomic_t do_add_files_print_progress = 0; static void @@ -101,7 +103,6 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b) static notmuch_status_t add_files_recursive (notmuch_database_t *notmuch, const char *path, - const char *tag, struct stat *st, add_files_state_t *state) { @@ -184,7 +185,6 @@ add_files_recursive (notmuch_database_t *notmuch, case NOTMUCH_STATUS_SUCCESS: state->added_messages++; tag_inbox_and_unread (message); - notmuch_message_add_tag (message, tag); break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: @@ -195,6 +195,7 @@ add_files_recursive (notmuch_database_t *notmuch, next); break; /* Fatal issues. Don't process anymore. */ + case NOTMUCH_STATUS_READONLY_DATABASE: case NOTMUCH_STATUS_XAPIAN_EXCEPTION: case NOTMUCH_STATUS_OUT_OF_MEMORY: fprintf (stderr, "Error: %s. Halting processing.\n", @@ -222,13 +223,7 @@ add_files_recursive (notmuch_database_t *notmuch, } } } else if (S_ISDIR (st->st_mode)) { - if ((strcmp (entry->d_name, "cur") == 0) || - (strcmp (entry->d_name, "new") == 0) || - (strcmp (entry->d_name, "tmp") == 0)) { - status = add_files_recursive (notmuch, next, tag, st, state); - } else { - status = add_files_recursive (notmuch, next, entry->d_name, st, state); - } + status = add_files_recursive (notmuch, next, st, state); if (status && ret == NOTMUCH_STATUS_SUCCESS) ret = status; } @@ -266,6 +261,7 @@ add_files (notmuch_database_t *notmuch, 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", @@ -279,31 +275,37 @@ add_files (notmuch_database_t *notmuch, } /* Setup our handler for SIGALRM */ - memset (&action, 0, sizeof (struct sigaction)); - action.sa_handler = handle_sigalrm; - sigemptyset (&action.sa_mask); - action.sa_flags = SA_RESTART; - sigaction (SIGALRM, &action, NULL); - - /* Then start a timer to send SIGALRM once per second. */ - timerval.it_interval.tv_sec = 1; - timerval.it_interval.tv_usec = 0; - timerval.it_value.tv_sec = 1; - timerval.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &timerval, NULL); + if (isatty (fileno (stdout)) && ! debugger_is_active ()) { + memset (&action, 0, sizeof (struct sigaction)); + action.sa_handler = handle_sigalrm; + sigemptyset (&action.sa_mask); + action.sa_flags = SA_RESTART; + sigaction (SIGALRM, &action, NULL); + + /* Then start a timer to send SIGALRM once per second. */ + timerval.it_interval.tv_sec = 1; + timerval.it_interval.tv_usec = 0; + timerval.it_value.tv_sec = 1; + timerval.it_value.tv_usec = 0; + setitimer (ITIMER_REAL, &timerval, NULL); + + timer_is_active = TRUE; + } - status = add_files_recursive (notmuch, path, basename(path), &st, state); + status = add_files_recursive (notmuch, path, &st, state); /* Now stop the timer. */ - timerval.it_interval.tv_sec = 0; - timerval.it_interval.tv_usec = 0; - timerval.it_value.tv_sec = 0; - timerval.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &timerval, NULL); - - /* And disable the signal handler. */ - action.sa_handler = SIG_IGN; - sigaction (SIGALRM, &action, NULL); + if (timer_is_active) { + timerval.it_interval.tv_sec = 0; + timerval.it_interval.tv_usec = 0; + timerval.it_value.tv_sec = 0; + timerval.it_value.tv_usec = 0; + setitimer (ITIMER_REAL, &timerval, NULL); + + /* And disable the signal handler. */ + action.sa_handler = SIG_IGN; + sigaction (SIGALRM, &action, NULL); + } return status; } @@ -420,7 +422,8 @@ notmuch_new_command (void *ctx, add_files_state.ignore_read_only_directories = FALSE; add_files_state.total_files = count; } else { - notmuch = notmuch_database_open (db_path); + notmuch = notmuch_database_open (db_path, + NOTMUCH_DATABASE_MODE_READ_WRITE); add_files_state.ignore_read_only_directories = TRUE; add_files_state.total_files = 0; }