From 959e8450affd1b9b5a6828fd0b0a202cbf6af45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 21 Oct 2020 14:01:27 +0200 Subject: [PATCH] crypto: Use a transaction to create sqlite tables. --- matrix_sdk_crypto/src/store/memorystore.rs | 1 + matrix_sdk_crypto/src/store/mod.rs | 1 + matrix_sdk_crypto/src/store/sqlite.rs | 36 ++++++++++++---------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index f41d4579..f7845dba 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -26,6 +26,7 @@ use matrix_sdk_common_macros::async_trait; use super::{ caches::{DeviceStore, GroupSessionStore, SessionStore}, + pickle_key::EncryptedPickleKey, Changes, CryptoStore, InboundGroupSession, ReadOnlyAccount, Result, Session, }; use crate::identities::{ReadOnlyDevice, UserIdentities}; diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 0753e672..23c1aeda 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -46,6 +46,7 @@ pub(crate) mod sqlite; use matrix_sdk_common::identifiers::DeviceIdBox; pub use memorystore::MemoryStore; +use pickle_key::EncryptedPickleKey; #[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "sqlite_cryptostore")] pub use sqlite::SqliteStore; diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 6759abb5..db9430f2 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -167,7 +167,9 @@ impl SqliteStore { async fn create_tables(&self) -> Result<()> { let mut connection = self.connection.lock().await; - connection + let mut transaction = connection.begin().await?; + + transaction .execute( r#" CREATE TABLE IF NOT EXISTS accounts ( @@ -183,7 +185,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS sessions ( @@ -202,7 +204,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS tracked_users ( @@ -220,7 +222,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS inbound_group_sessions ( @@ -241,7 +243,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS group_session_claimed_keys ( @@ -259,7 +261,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS group_session_chains ( @@ -276,7 +278,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS devices ( @@ -296,7 +298,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS algorithms ( @@ -313,7 +315,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS device_keys ( @@ -331,7 +333,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS device_signatures ( @@ -350,7 +352,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS users ( @@ -367,7 +369,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS users_trust_state ( @@ -382,7 +384,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS cross_signing_keys ( @@ -399,7 +401,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS user_keys ( @@ -416,7 +418,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS user_key_signatures ( @@ -435,7 +437,7 @@ impl SqliteStore { ) .await?; - connection + transaction .execute( r#" CREATE TABLE IF NOT EXISTS key_value ( @@ -453,6 +455,8 @@ impl SqliteStore { ) .await?; + transaction.commit().await?; + Ok(()) }