diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-03-22 07:31:33 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-03-22 07:31:33 +0100 |
| commit | 199e066d8c92287f0868fceec9f719e1c6005df2 (patch) | |
| tree | 1d22533dd3722946dabeb2532c4f421065f11462 | |
| parent | db6f7a872ae5404e813f461b63e3f3d8158a3a8d (diff) | |
| download | mail-199e066d8c92287f0868fceec9f719e1c6005df2.tar.gz | |
get notmuch db revision
| -rw-r--r-- | src/database.rs | 18 | ||||
| -rw-r--r-- | src/ffi.rs | 2 | ||||
| -rw-r--r-- | 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<P: AsRef<path::Path>>(path: &P, mode: DatabaseOpenMode) -> Result<Database> { + pub fn open<P: AsRef<path::Path>>(path: &P, mode: DatabaseMode) -> Result<Database> { 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 @@ -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 } @@ -11,4 +11,4 @@ pub mod database; pub mod directory; pub use database::Database; -pub use ffi::DatabaseOpenMode; +pub use ffi::DatabaseMode; |
