struct NmAccountData *adata = *ptr;
if (adata->db)
{
-#ifdef NOTMUCH_API_3
- notmuch_database_destroy(adata->db);
-#else
- notmuch_database_close(adata->db);
-#endif
+ nm_db_free(adata->db);
adata->db = NULL;
}
done:
if (db)
{
-#ifdef NOTMUCH_API_3
- notmuch_database_destroy(db);
-#else
- notmuch_database_close(db);
-#endif
+ nm_db_free(db);
mutt_debug(1, "nm: count close DB\n");
}
url_free(&url);
return NULL;
char *db_filename = mdata->db_url.path ? mdata->db_url.path : NmDefaultUri;
- if (!db_filename)
- db_filename = Folder;
- if (!db_filename)
+ if (!db_filename && !Folder)
return NULL;
+
+ db_filename = Folder;
+
if (nm_path_probe(db_filename, NULL) == MUTT_NOTMUCH)
db_filename += NmUriProtocolLen;
*/
notmuch_database_t *nm_db_get(struct Mailbox *m, bool writable)
{
- if (!m || (m->magic != MUTT_NOTMUCH))
- return NULL;
- struct Account *a = m->account;
- if (!a)
- return NULL;
- struct NmAccountData *adata = a->adata;
+ struct NmAccountData *adata = nm_adata_get(m);
+
if (!adata)
return NULL;
return -1;
mutt_debug(1, "nm: db close\n");
-#ifdef NOTMUCH_API_3
- notmuch_database_destroy(adata->db);
-#else
- notmuch_database_close(adata->db);
-#endif
+ nm_db_free(adata->db);
adata->db = NULL;
adata->longrun = false;
return 0;
}
+/**
+ * nm_db_free - decoupled way to close a Notmuch database
+ * @param db Notmuch database
+ */
+void nm_db_free(notmuch_database_t *db)
+{
+#ifdef NOTMUCH_API_3
+ notmuch_database_destroy(db);
+#else
+ notmuch_database_close(db);
+#endif
+}
+
/**
* nm_db_trans_begin - Start a Notmuch database transaction
* @param m Mailbox
void nm_db_debug_check (struct Mailbox *m);
notmuch_database_t *nm_db_do_open (const char *filename, bool writable, bool verbose);
+void nm_db_free (notmuch_database_t *db);
const char * nm_db_get_filename(struct Mailbox *m);
int nm_db_get_mtime (struct Mailbox *m, time_t *mtime);
notmuch_database_t *nm_db_get (struct Mailbox *m, bool writable);