From edf986b7888a97ad434f08c1900d5ae4356ec44a Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Wed, 23 Oct 2019 06:55:03 +0200 Subject: fix index_file and add freeze/thaw --- src/database.rs | 18 +++++++++++------- src/lib.rs | 4 +++- src/message.rs | 8 ++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/database.rs b/src/database.rs index c26b5a8..f3733ef 100644 --- a/src/database.rs +++ b/src/database.rs @@ -249,12 +249,20 @@ impl Database { ::get_default_indexopts(self) } - pub fn index_file<'d, P>(&'d self, path: &P, indexopts: Option>) -> Result>> + pub fn index_file<'d, P>(&'d self, path: &P, indexopts: Option>) -> Result> where P: AsRef, { ::index_file(self, path, indexopts) } + + pub fn begin_atomic(&self) -> Result<()> { + unsafe { ffi::notmuch_database_begin_atomic(self.ptr) }.as_result() + } + + pub fn end_atomic(&self) -> Result<()> { + unsafe { ffi::notmuch_database_end_atomic(self.ptr) }.as_result() + } } pub trait DatabaseExt { @@ -370,7 +378,7 @@ pub trait DatabaseExt { } - fn index_file<'d, D, P>(database: D, path: &P, indexopts: Option>) -> Result>> + fn index_file<'d, D, P>(database: D, path: &P, indexopts: Option>) -> Result> where D: Into>, P: AsRef, @@ -387,11 +395,7 @@ pub trait DatabaseExt { unsafe { ffi::notmuch_database_index_file(dbref.ptr, msg_path.as_ptr(), opts, &mut msg) } .as_result()?; - if msg.is_null() { - Ok(None) - } else { - Ok(Some(Message::from_ptr(msg, Supercow::phantom(dbref)))) - } + Ok(Message::from_ptr(msg, Supercow::phantom(dbref))) } None => Err(Error::NotmuchError(Status::FileError)), } diff --git a/src/lib.rs b/src/lib.rs index 2d43f21..0336e8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,4 +34,6 @@ pub use thread::{Thread, ThreadExt}; pub use threads::{Threads, ThreadsExt}; pub use index::IndexOpts; -pub use ffi::{DatabaseMode, Sort, DecryptionPolicy}; \ No newline at end of file +pub use ffi::{DatabaseMode, Sort, DecryptionPolicy}; + +pub use utils::{ScopedSupercow, ScopedPhantomcow}; \ No newline at end of file diff --git a/src/message.rs b/src/message.rs index 73727f9..f5d0542 100644 --- a/src/message.rs +++ b/src/message.rs @@ -123,6 +123,14 @@ where pub fn reindex<'d>(self: &Self, indexopts: IndexOpts<'d>) -> Result<()> { unsafe { ffi::notmuch_message_reindex(self.ptr, indexopts.ptr) }.as_result() } + + pub fn freeze(self: &Self) -> Result<()> { + unsafe { ffi::notmuch_message_freeze(self.ptr) }.as_result() + } + + pub fn thaw(self: &Self) -> Result<()> { + unsafe { ffi::notmuch_message_thaw(self.ptr) }.as_result() + } } pub trait MessageExt<'o, O> -- cgit v1.2.1