base: Swap around the store creation.

The state store creates directory structure but the crypto store does
not.

This can lead to confusing errors where we require a directory to be
created by the library user but it gets created by the library.
master
Damir Jelić 2020-07-06 10:54:01 +02:00
parent 669a3f22d2
commit 11aa306de2
1 changed files with 14 additions and 14 deletions

View File

@ -458,6 +458,20 @@ impl BaseClient {
/// * `session` - An session that the user already has from a
/// previous login call.
pub async fn restore_login(&self, session: Session) -> Result<()> {
// If there wasn't a state store opened, try to open the default one if
// a store path was provided.
if self.state_store.read().await.is_none() {
#[cfg(not(target_arch = "wasm32"))]
{
if let Some(path) = &*self.store_path {
let store = JsonStore::open(path)?;
*self.state_store.write().await = Some(Box::new(store));
}
}
}
self.sync_with_state_store(&session).await?;
#[cfg(feature = "encryption")]
{
let mut olm = self.olm.lock().await;
@ -496,20 +510,6 @@ impl BaseClient {
}
}
// If there wasn't a state store opened, try to open the default one if
// a store path was provided.
if self.state_store.read().await.is_none() {
#[cfg(not(target_arch = "wasm32"))]
{
if let Some(path) = &*self.store_path {
let store = JsonStore::open(path)?;
*self.state_store.write().await = Some(Box::new(store));
}
}
}
self.sync_with_state_store(&session).await?;
*self.session.write().await = Some(session);
Ok(())