From: Karel Zak Date: Mon, 16 Apr 2012 10:33:11 +0000 (+0200) Subject: add nm_open_timeout X-Git-Tag: neomutt-20160404~13^2~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71c0ccf674b892f6ba60c7b12f14f8a5b4ce7d71;p=neomutt add nm_open_timeout Signed-off-by: Karel Zak --- diff --git a/README.notmuch b/README.notmuch index 9d103cb7d..564722057 100644 --- a/README.notmuch +++ b/README.notmuch @@ -115,6 +115,10 @@ notmuch support for mutt the sidebar. It's possible to toggle between virtual and normal folders by sidebar-toggle command. + notmuch_open_timeout = + + This option specifies timeout for Notmuch database. Default is 5 seconds. + notmuch_default_uri = This variable specifies the default Notmuch database in format diff --git a/globals.h b/globals.h index 276d5d468..95d9f1229 100644 --- a/globals.h +++ b/globals.h @@ -282,6 +282,7 @@ WHERE char *SmimeImportCertCommand; WHERE char *SmimeGetCertEmailCommand; #ifdef USE_NOTMUCH +WHERE int NotmuchOpenTimeout; WHERE char *NotmuchDefaultUri; WHERE char *NotmuchUnreadTag; WHERE char *NotmuchHiddenTags; diff --git a/init.h b/init.h index 485acd150..9145100ec 100644 --- a/init.h +++ b/init.h @@ -1669,6 +1669,12 @@ struct option_t MuttVars[] = { */ #endif #ifdef USE_NOTMUCH + { "nm_open_timeout", DT_NUM, R_NONE, UL &NotmuchOpenTimeout, 5 }, + /* + ** .pp + ** This variable specifies the timeout for database open in seconds. + */ + { "nm_default_uri", DT_STR, R_NONE, UL &NotmuchDefaultUri, 0 }, /* ** .pp diff --git a/mutt_notmuch.c b/mutt_notmuch.c index e75b73470..a3378dcb9 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -342,6 +342,36 @@ static const char *get_db_filename(struct nm_ctxdata *data) return db_filename; } +static notmuch_database_t *do_database_open(const char *filename, + int writable, int verbose) +{ + notmuch_database_t *db = NULL; + unsigned int ct = 0; + + dprint(1, (debugfile, "nm: db open '%s' %s (timeout %d)\n", filename, + writable ? "[WRITE]" : "[READ]", NotmuchOpenTimeout)); + do { + db = notmuch_database_open(filename, + writable ? NOTMUCH_DATABASE_MODE_READ_WRITE : + NOTMUCH_DATABASE_MODE_READ_ONLY); + if (db || !NotmuchOpenTimeout || ct / 2 > NotmuchOpenTimeout) + break; + + if (verbose && ct && ct % 2 == 0) + mutt_error(_("Waiting for notmuch DB... (%d sec)"), ct / 2); + usleep(500000); + ct++; + } while (1); + + if (verbose) { + if (!db) + mutt_error (_("Cannot open notmuch database: %s"), filename); + else if (ct > 1) + mutt_clear_error(); + } + return db; +} + static notmuch_database_t *get_db(struct nm_ctxdata *data, int writable) { if (!data) @@ -349,20 +379,9 @@ static notmuch_database_t *get_db(struct nm_ctxdata *data, int writable) if (!data->db) { const char *db_filename = get_db_filename(data); - if (!db_filename) - return NULL; - - dprint(1, (debugfile, "nm: db open '%s' %s\n", db_filename, - writable ? "[WRITE]" : "[READ]")); - - data->db = notmuch_database_open(db_filename, - writable ? NOTMUCH_DATABASE_MODE_READ_WRITE : - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (!data->db) - mutt_error (_("Cannot open notmuch database: %s"), - db_filename); + if (db_filename) + data->db = do_database_open(db_filename, writable, TRUE); } - return data->db; } @@ -987,12 +1006,11 @@ int nm_nonctx_get_count(char *path, int *all, int *new) dflt = 1; } - dprint(1, (debugfile, "nm: count open DB\n")); - db = notmuch_database_open(db_filename, NOTMUCH_DATABASE_MODE_READ_ONLY); - if (!db) { - mutt_error (_("Cannot open notmuch database: %s"), db_filename); + /* don't be verbose about connection, as we're called from + * sidebar/buffy very often */ + db = do_database_open(db_filename, FALSE, FALSE); + if (!db) goto done; - } /* all emails */ if (all)