mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-17 04:58:41 -04:00
moving make_store_config features back to sled, fxies #562
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "state-store")]
|
||||
use matrix_sdk_base::store::StoreError;
|
||||
use matrix_sdk_base::store::{StoreError, StoreConfig};
|
||||
#[cfg(feature = "crypto-store")]
|
||||
use matrix_sdk_crypto::store::CryptoStoreError;
|
||||
use sled::Error as SledError;
|
||||
@@ -34,3 +34,59 @@ pub enum OpenStoreError {
|
||||
#[error(transparent)]
|
||||
Sled(#[from] SledError),
|
||||
}
|
||||
|
||||
|
||||
// FIXME Move these two methods back to the matrix-sdk-sled crate once weak
|
||||
// dependency features are stable and we decide to bump the MSRV.
|
||||
|
||||
/// Create a [`StoreConfig`] with an opened sled [`StateStore`] that uses the
|
||||
/// given path and passphrase. If `encryption` is enabled, a [`CryptoStore`]
|
||||
/// with the same parameters is also opened.
|
||||
///
|
||||
/// [`StoreConfig`]: #StoreConfig
|
||||
#[cfg(any(feature = "state-store", feature = "crypto-store"))]
|
||||
pub fn make_store_config(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<StoreConfig, OpenStoreError> {
|
||||
#[cfg(all(feature = "crypto-store", feature = "state-store"))]
|
||||
{
|
||||
let (state_store, crypto_store) = open_stores_with_path(path, passphrase)?;
|
||||
Ok(StoreConfig::new().state_store(state_store).crypto_store(crypto_store))
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "crypto-store", not(feature = "state-store")))]
|
||||
{
|
||||
let crypto_store = CryptoStore::open_with_passphrase(path, passphrase)?;
|
||||
Ok(StoreConfig::new().crypto_store(Box::new(crypto_store)))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "crypto-store"))]
|
||||
{
|
||||
let state_store = if let Some(passphrase) = passphrase {
|
||||
StateStore::open_with_passphrase(path, passphrase)?
|
||||
} else {
|
||||
StateStore::open_with_path(path)?
|
||||
};
|
||||
|
||||
Ok(StoreConfig::new().state_store(Box::new(state_store)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a [`StateStore`] and a [`CryptoStore`] that use the same database and
|
||||
/// passphrase.
|
||||
#[cfg(all(feature = "state-store", feature = "crypto-store"))]
|
||||
fn open_stores_with_path(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<(Box<StateStore>, Box<CryptoStore>), OpenStoreError> {
|
||||
if let Some(passphrase) = passphrase {
|
||||
let state_store = StateStore::open_with_passphrase(path, passphrase)?;
|
||||
let crypto_store = state_store.open_crypto_store(Some(passphrase))?;
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
} else {
|
||||
let state_store = StateStore::open_with_path(path)?;
|
||||
let crypto_store = state_store.open_crypto_store(None)?;
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,4 +160,4 @@ required-features = ["encryption"]
|
||||
|
||||
[[example]]
|
||||
name = "timeline"
|
||||
required-features = ["sled-state-store"]
|
||||
required-features = ["sled"]
|
||||
|
||||
@@ -44,7 +44,7 @@ async fn login_and_sync(
|
||||
#[allow(unused_mut)]
|
||||
let mut client_builder = Client::builder().homeserver_url(homeserver_url);
|
||||
|
||||
#[cfg(feature = "sled-state-store")]
|
||||
#[cfg(feature = "sled")]
|
||||
{
|
||||
// The location to save files to
|
||||
let mut home = dirs::home_dir().expect("no home directory found");
|
||||
@@ -53,7 +53,7 @@ async fn login_and_sync(
|
||||
client_builder = client_builder.state_store(Box::new(state_store));
|
||||
}
|
||||
|
||||
#[cfg(feature = "indexeddb-state-store")]
|
||||
#[cfg(feature = "indexeddb")]
|
||||
{
|
||||
let state_store = matrix_sdk_indexeddb::StateStore::open();
|
||||
client_builder = client_builder.state_store(Box::new(state_store));
|
||||
|
||||
@@ -39,7 +39,7 @@ async fn login_and_sync(
|
||||
#[allow(unused_mut)]
|
||||
let mut client_builder = Client::builder().homeserver_url(homeserver_url);
|
||||
|
||||
#[cfg(feature = "sled-state-store")]
|
||||
#[cfg(feature = "sled")]
|
||||
{
|
||||
// The location to save files to
|
||||
let mut home = dirs::home_dir().expect("no home directory found");
|
||||
@@ -48,7 +48,7 @@ async fn login_and_sync(
|
||||
client_builder = client_builder.state_store(Box::new(state_store));
|
||||
}
|
||||
|
||||
#[cfg(feature = "indexeddb-state-store")]
|
||||
#[cfg(feature = "indexeddb")]
|
||||
{
|
||||
let state_store = matrix_sdk_indexeddb::StateStore::open();
|
||||
client_builder = client_builder.state_store(Box::new(state_store));
|
||||
|
||||
@@ -29,62 +29,7 @@
|
||||
//! [`StoreConfig`]: crate::config::StoreConfig
|
||||
//! [`ClientBuilder::store_config()`]: crate::ClientBuilder::store_config
|
||||
|
||||
#[cfg(any(feature = "indexeddb-state-store", feature = "indexeddb-crypto-store"))]
|
||||
#[cfg(feature = "indexeddb")]
|
||||
pub use matrix_sdk_indexeddb::*;
|
||||
#[cfg(any(feature = "sled-state-store", feature = "sled-crypto-store"))]
|
||||
pub use matrix_sdk_sled::*;
|
||||
|
||||
// FIXME Move these two methods back to the matrix-sdk-sled crate once weak
|
||||
// dependency features are stable and we decide to bump the MSRV.
|
||||
|
||||
/// Create a [`StoreConfig`] with an opened sled [`StateStore`] that uses the
|
||||
/// given path and passphrase. If `encryption` is enabled, a [`CryptoStore`]
|
||||
/// with the same parameters is also opened.
|
||||
///
|
||||
/// [`StoreConfig`]: #crate::config::StoreConfig
|
||||
#[cfg(any(feature = "sled-state-store", feature = "sled-crypto-store"))]
|
||||
pub fn make_store_config(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<crate::config::StoreConfig, OpenStoreError> {
|
||||
#[cfg(all(feature = "e2e-encryption", feature = "sled-state-store"))]
|
||||
{
|
||||
let (state_store, crypto_store) = open_stores_with_path(path, passphrase)?;
|
||||
Ok(crate::config::StoreConfig::new().state_store(state_store).crypto_store(crypto_store))
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "e2e-encryption", not(feature = "sled-state-store")))]
|
||||
{
|
||||
let crypto_store = CryptoStore::open_with_passphrase(path, passphrase)?;
|
||||
Ok(crate::config::StoreConfig::new().crypto_store(Box::new(crypto_store)))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "e2e-encryption"))]
|
||||
{
|
||||
let state_store = if let Some(passphrase) = passphrase {
|
||||
StateStore::open_with_passphrase(path, passphrase)?
|
||||
} else {
|
||||
StateStore::open_with_path(path)?
|
||||
};
|
||||
|
||||
Ok(crate::config::StoreConfig::new().state_store(Box::new(state_store)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a [`StateStore`] and a [`CryptoStore`] that use the same database and
|
||||
/// passphrase.
|
||||
#[cfg(all(feature = "sled-state-store", feature = "sled-crypto-store"))]
|
||||
fn open_stores_with_path(
|
||||
path: impl AsRef<std::path::Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<(Box<StateStore>, Box<CryptoStore>), OpenStoreError> {
|
||||
if let Some(passphrase) = passphrase {
|
||||
let state_store = StateStore::open_with_passphrase(path, passphrase)?;
|
||||
let crypto_store = state_store.open_crypto_store(Some(passphrase))?;
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
} else {
|
||||
let state_store = StateStore::open_with_path(path)?;
|
||||
let crypto_store = state_store.open_crypto_store(None)?;
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "sled")]
|
||||
pub use matrix_sdk_sled::*;
|
||||
Reference in New Issue
Block a user