From 199e066d8c92287f0868fceec9f719e1c6005df2 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Thu, 22 Mar 2018 07:31:33 +0100 Subject: get notmuch db revision --- src/database.rs | 18 +++++++++++++++--- src/ffi.rs | 2 +- src/lib.rs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/database.rs b/src/database.rs index 8f64fdd..a809e3d 100644 --- a/src/database.rs +++ b/src/database.rs @@ -19,11 +19,14 @@ use directory::Directory; use ffi; // Re-exported under database module for pretty namespacin'. -pub use ffi::DatabaseOpenMode; +pub use ffi::DatabaseMode; #[derive(Copy, Clone, Debug)] pub struct Version(libc::c_uint); +#[derive(Copy, Clone, Debug)] +pub struct Revision(libc::c_ulong); + #[derive(Debug)] pub struct Database(*mut ffi::notmuch_database_t); @@ -39,13 +42,15 @@ impl Database { Ok(Database(db)) } - pub fn open>(path: &P, mode: DatabaseOpenMode) -> Result { + pub fn open>(path: &P, mode: DatabaseMode) -> Result { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); try!(unsafe { ffi::notmuch_database_open( - path_str.as_ptr(), mode.into(), &mut db, + path_str.as_ptr(), + mode.into(), + &mut db, ) }.as_result()); @@ -117,6 +122,13 @@ impl Database { }) } + pub fn revision(&self) -> Revision { + let uuid = ptr::null_mut(); + Revision(unsafe { + ffi::notmuch_database_get_revision(self.0, uuid) + }) + } + pub fn needs_upgrade(&self) -> bool { unsafe { ffi::notmuch_database_needs_upgrade(self.0) == 1 diff --git a/src/ffi.rs b/src/ffi.rs index f3ddb41..b5dcca3 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -85,7 +85,7 @@ impl error::Error for Status { notmuch_enum! { #[repr(C)] #[derive(Debug, Eq, PartialEq, Clone, Copy)] - pub enum notmuch_database_mode_t => DatabaseOpenMode { + pub enum notmuch_database_mode_t => DatabaseMode { NOTMUCH_DATABASE_MODE_READ_ONLY => ReadOnly, NOTMUCH_DATABASE_MODE_READ_WRITE => ReadWrite } diff --git a/src/lib.rs b/src/lib.rs index 1348c7e..7ee28ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,4 +11,4 @@ pub mod database; pub mod directory; pub use database::Database; -pub use ffi::DatabaseOpenMode; +pub use ffi::DatabaseMode; -- cgit v1.2.1