mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
api: add ContextBuilder.build() to build Context without opening
This commit is contained in:
@@ -153,11 +153,19 @@ impl ContextBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Opens the [`Context`].
|
/// Builds the [`Context`] without opening it.
|
||||||
pub async fn open(self) -> Result<Context> {
|
pub async fn build(self) -> Result<Context> {
|
||||||
let context =
|
let context =
|
||||||
Context::new_closed(&self.dbfile, self.id, self.events, self.stock_strings).await?;
|
Context::new_closed(&self.dbfile, self.id, self.events, self.stock_strings).await?;
|
||||||
let password = self.password.unwrap_or_default();
|
Ok(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds the [`Context`] and opens it.
|
||||||
|
///
|
||||||
|
/// Returns error if context cannot be opened with the given passphrase.
|
||||||
|
pub async fn open(self) -> Result<Context> {
|
||||||
|
let password = self.password.clone().unwrap_or_default();
|
||||||
|
let context = self.build().await?;
|
||||||
match context.open(password).await? {
|
match context.open(password).await? {
|
||||||
true => Ok(context),
|
true => Ok(context),
|
||||||
false => bail!("database could not be decrypted, incorrect or missing password"),
|
false => bail!("database could not be decrypted, incorrect or missing password"),
|
||||||
|
|||||||
Reference in New Issue
Block a user