return notmuch;
}
+notmuch_status_t
+_notmuch_database_ensure_writable (notmuch_database_t *notmuch)
+{
+ if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
+ fprintf (stderr, "Cannot write to a read-only database.\n");
+ return NOTMUCH_STATUS_READONLY_DATABASE;
+ }
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
notmuch_database_t *
notmuch_database_open (const char *path,
notmuch_database_mode_t mode)
if (message_ret)
*message_ret = NULL;
+ ret = _notmuch_database_ensure_writable (notmuch);
+ if (ret)
+ return ret;
+
message_file = notmuch_message_file_open (filename);
- if (message_file == NULL) {
- ret = NOTMUCH_STATUS_FILE_ERROR;
- goto DONE;
- }
+ if (message_file == NULL)
+ return NOTMUCH_STATUS_FILE_ERROR;
notmuch_message_file_restrict_headers (message_file,
"date",
Xapian::Document document;
notmuch_status_t status;
- if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
- fprintf (stderr, "Attempted to update a read-only database.\n");
- return NOTMUCH_STATUS_READONLY_DATABASE;
- }
+ status = _notmuch_database_ensure_writable (notmuch);
+ if (status)
+ return status;
db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);