// Status codes used for the return values of most functions
type Status C.notmuch_status_t
const (
- STATUS_SUCCESS Status = 0
+ STATUS_SUCCESS Status = iota
STATUS_OUT_OF_MEMORY
STATUS_READ_ONLY_DATABASE
STATUS_XAPIAN_EXCEPTION
STATUS_NULL_POINTER
STATUS_TAG_TOO_LONG
STATUS_UNBALANCED_FREEZE_THAW
+ STATUS_UNBALANCED_ATOMIC
STATUS_LAST_STATUS
)
)
// Create a new, empty notmuch database located at 'path'
-func NewDatabase(path string) *Database {
+func NewDatabase(path string) (*Database, Status) {
var c_path *C.char = C.CString(path)
defer C.free(unsafe.Pointer(c_path))
if c_path == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
self := &Database{db:nil}
- self.db = C.notmuch_database_create(c_path)
- if self.db == nil {
- return nil
+ st := Status(C.notmuch_database_create(c_path, &self.db))
+ if st != STATUS_SUCCESS {
+ return nil, st
}
- return self
+ return self, st
}
/* Open an existing notmuch database located at 'path'.
* An existing notmuch database can be identified by the presence of a
* directory named ".notmuch" below 'path'.
*
- * The caller should call notmuch_database_close when finished with
+ * The caller should call notmuch_database_destroy when finished with
* this database.
*
* In case of any failure, this function returns NULL, (after printing
* an error message on stderr).
*/
-func OpenDatabase(path string, mode DatabaseMode) *Database {
+func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) {
var c_path *C.char = C.CString(path)
defer C.free(unsafe.Pointer(c_path))
if c_path == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
self := &Database{db:nil}
- self.db = C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode))
- if self.db == nil {
- return nil
+ st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db))
+ if st != STATUS_SUCCESS {
+ return nil, st
}
- return self
+ return self, st
}
/* Close the given notmuch database, freeing all associated
* resources. See notmuch_database_open. */
func (self *Database) Close() {
- C.notmuch_database_close(self.db)
+ C.notmuch_database_destroy(self.db)
}
/* Return the database path of the given database.
* * An out-of-memory situation occurs
* * A Xapian exception occurs
*/
-func (self *Database) FindMessage(message_id string) *Message {
+func (self *Database) FindMessage(message_id string) (*Message, Status) {
var c_msg_id *C.char = C.CString(message_id)
defer C.free(unsafe.Pointer(c_msg_id))
if c_msg_id == nil {
- return nil
+ return nil, STATUS_OUT_OF_MEMORY
}
- msg := C.notmuch_database_find_message(self.db, c_msg_id)
- if msg == nil {
- return nil
+ msg := &Message{message:nil}
+ st := Status(C.notmuch_database_find_message(self.db, c_msg_id, &msg.message))
+ if st != STATUS_SUCCESS {
+ return nil, st
}
- return &Message{message:msg}
+ return msg, st
}
/* Return a list of all tags found in the database.