From: Richard Russon Date: Tue, 27 Feb 2018 13:29:44 +0000 (+0000) Subject: notmuch: stop if db open fails X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9343ad9a1ebed339316e32e0fe7557d4b2101f3c;p=neomutt notmuch: stop if db open fails * If the database open fails, stop * Use the verbose version of open so we can catch the error message issue #1076 --- diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 76ca5fc8b..855fbe3dc 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -482,19 +482,24 @@ static notmuch_database_t *do_database_open(const char *filename, bool writable, notmuch_database_t *db = NULL; int ct = 0; notmuch_status_t st = NOTMUCH_STATUS_SUCCESS; + char *msg = NULL; mutt_debug(1, "nm: db open '%s' %s (timeout %d)\n", filename, writable ? "[WRITE]" : "[READ]", NmOpenTimeout); do { -#ifdef NOTMUCH_API_3 +#if LIBNOTMUCH_CHECK_VERSION(4, 3, 0) + st = notmuch_database_open_verbose( + filename, writable ? NOTMUCH_DATABASE_MODE_READ_WRITE : NOTMUCH_DATABASE_MODE_READ_ONLY, + &db, &msg); +#elif defined(NOTMUCH_API_3) st = notmuch_database_open(filename, writable ? NOTMUCH_DATABASE_MODE_READ_WRITE : NOTMUCH_DATABASE_MODE_READ_ONLY, &db); #else db = notmuch_database_open(filename, writable ? NOTMUCH_DATABASE_MODE_READ_WRITE : NOTMUCH_DATABASE_MODE_READ_ONLY); #endif - if (db || !NmOpenTimeout || ((ct / 2) > NmOpenTimeout)) + if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !NmOpenTimeout || ((ct / 2) > NmOpenTimeout)) break; if (verbose && ct && ((ct % 2) == 0)) @@ -506,10 +511,22 @@ static notmuch_database_t *do_database_open(const char *filename, bool writable, if (verbose) { if (!db) - mutt_error(_("Cannot open notmuch database: %s: %s"), filename, - st ? notmuch_status_to_string(st) : _("unknown reason")); + { + if (msg) + { + mutt_error(msg); + FREE(&msg); + } + else + { + mutt_error(_("Cannot open notmuch database: %s: %s"), filename, + st ? notmuch_status_to_string(st) : _("unknown reason")); + } + } else if (ct > 1) + { mutt_clear_error(); + } } return db; }