From 318f7e2a7361f3ba5bb58ba29d17b5c976c294f5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 19 Apr 2023 23:24:35 +0200 Subject: [PATCH] Update vault --- Cargo.lock | 30 ++++++---- Cargo.toml | 4 +- src/ui.rs | 2 +- src/vault.rs | 7 ++- src/vault/euph.rs | 146 +++++++++++++++++++++++++++------------------- 5 files changed, 112 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd844fd..540a3cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,6 +103,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c70beb79cbb5ce9c4f8e20849978f34225931f665bb49efa6982875a4d5facb3" + [[package]] name = "block-buffer" version = "0.10.4" @@ -171,7 +177,7 @@ checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" dependencies = [ "anstream", "anstyle", - "bitflags", + "bitflags 1.3.2", "clap_lex", "strsim", ] @@ -281,7 +287,7 @@ version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" dependencies = [ - "bitflags", + "bitflags 1.3.2", "crossterm_winapi", "libc", "mio", @@ -617,9 +623,9 @@ checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "libsqlite3-sys" -version = "0.25.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" +checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" dependencies = [ "cc", "pkg-config", @@ -822,7 +828,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -831,7 +837,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -879,11 +885,11 @@ dependencies = [ [[package]] name = "rusqlite" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" +checksum = "549b9d036d571d42e6e85d1c1425e2ac83491075078ca9a15be021c56b1641f2" dependencies = [ - "bitflags", + "bitflags 2.1.0", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -898,7 +904,7 @@ version = "0.37.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", @@ -976,7 +982,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -1424,7 +1430,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "vault" version = "0.1.0" -source = "git+https://github.com/Garmelon/vault.git?tag=v0.1.0#028c72cac4e84bfbbf9fb03b15acb59989a31df9" +source = "git+https://github.com/Garmelon/vault.git?rev=b4cf23b7279770226725c895e482c8eda88c43a7#b4cf23b7279770226725c895e482c8eda88c43a7" dependencies = [ "rusqlite", "tokio", diff --git a/Cargo.toml b/Cargo.toml index f0e55ee..61abd7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ log = { version = "0.4.17", features = ["std"] } once_cell = "1.17.1" open = "4.0.1" parking_lot = "0.12.1" -rusqlite = { version = "0.28.0", features = ["bundled", "time"] } +rusqlite = { version = "0.29.0", features = ["bundled", "time"] } serde = { version = "1.0.159", features = ["derive"] } serde_json = "1.0.95" thiserror = "1.0.40" @@ -50,7 +50,7 @@ rev = "f414db40d526295c74cbcae6c3d194088da8f1d9" [dependencies.vault] git = "https://github.com/Garmelon/vault.git" -tag = "v0.1.0" +rev = "b4cf23b7279770226725c895e482c8eda88c43a7" features = ["tokio"] # [patch."https://github.com/Garmelon/vault.git"] diff --git a/src/ui.rs b/src/ui.rs index 05ecbaa..42235bf 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -36,7 +36,7 @@ const EVENT_PROCESSING_TIME: Duration = Duration::from_millis(1000 / 15); // 15 #[derive(Debug, thiserror::Error)] pub enum UiError { #[error("{0}")] - Vault(#[from] vault::tokio::Error), + Vault(#[from] vault::tokio::Error), #[error("{0}")] Io(#[from] io::Error), } diff --git a/src/vault.rs b/src/vault.rs index 4f49e45..921ad4d 100644 --- a/src/vault.rs +++ b/src/vault.rs @@ -20,9 +20,10 @@ pub struct Vault { struct GcAction; impl Action for GcAction { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { conn.execute_batch("ANALYZE; VACUUM;") } } @@ -36,7 +37,7 @@ impl Vault { self.tokio_vault.stop().await; } - pub async fn gc(&self) -> vault::tokio::Result<()> { + pub async fn gc(&self) -> Result<(), vault::tokio::Error> { self.tokio_vault.execute(GcAction).await } diff --git a/src/vault/euph.rs b/src/vault/euph.rs index 49f1501..e9f363e 100644 --- a/src/vault/euph.rs +++ b/src/vault/euph.rs @@ -88,7 +88,7 @@ macro_rules! euph_vault_actions { impl EuphVault { $( - pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> vault::tokio::Result<$res> { + pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> Result<$res, vault::tokio::Error> { self.vault.tokio_vault.execute($struct { $( $arg, )* }).await } )* @@ -103,9 +103,10 @@ euph_vault_actions! { } impl Action for GetCookies { - type Result = CookieJar; + type Output = CookieJar; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let cookies = conn .prepare( " @@ -128,9 +129,10 @@ impl Action for GetCookies { } impl Action for SetCookies { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let tx = conn.transaction()?; // Since euphoria sets all cookies on every response, we can just delete @@ -154,9 +156,10 @@ impl Action for SetCookies { } impl Action for GetRooms { - type Result = Vec; + type Output = Vec; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { conn.prepare( " SELECT room @@ -201,7 +204,7 @@ macro_rules! euph_room_vault_actions { impl EuphRoomVault { $( - pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> vault::tokio::Result<$res> { + pub async fn $fn(&self, $( $arg: $arg_ty, )* ) -> Result<$res, vault::tokio::Error> { self.vault.vault.tokio_vault.execute($struct { room: self.room.clone(), $( $arg, )* @@ -244,9 +247,10 @@ euph_room_vault_actions! { } impl Action for Join { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { conn.execute( " INSERT INTO euph_rooms (room, first_joined, last_joined) @@ -261,9 +265,10 @@ impl Action for Join { } impl Action for Delete { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { conn.execute( " DELETE FROM euph_rooms @@ -431,9 +436,10 @@ fn add_span( } impl Action for AddMsg { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let tx = conn.transaction()?; let end = self.msg.id; @@ -446,9 +452,10 @@ impl Action for AddMsg { } impl Action for AddMsgs { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let tx = conn.transaction()?; if self.msgs.is_empty() { @@ -469,9 +476,10 @@ impl Action for AddMsgs { } impl Action for GetLastSpan { - type Result = Option<(Option, Option)>; + type Output = Option<(Option, Option)>; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let span = conn .prepare( " @@ -494,9 +502,10 @@ impl Action for GetLastSpan { } impl Action for GetPath { - type Result = Path; + type Output = Path; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let path = conn .prepare( " @@ -523,9 +532,10 @@ impl Action for GetPath { } impl Action for GetMsg { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg = conn .query_row( " @@ -552,9 +562,10 @@ impl Action for GetMsg { } impl Action for GetFullMsg { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let mut query = conn.prepare( " SELECT @@ -597,9 +608,10 @@ impl Action for GetFullMsg { } impl Action for GetTree { - type Result = Tree; + type Output = Tree; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msgs = conn .prepare( " @@ -635,9 +647,10 @@ impl Action for GetTree { } impl Action for GetFirstRootId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let root_id = conn .prepare( " @@ -657,9 +670,10 @@ impl Action for GetFirstRootId { } impl Action for GetLastRootId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let root_id = conn .prepare( " @@ -679,9 +693,10 @@ impl Action for GetLastRootId { } impl Action for GetPrevRootId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let root_id = conn .prepare( " @@ -702,9 +717,10 @@ impl Action for GetPrevRootId { } impl Action for GetNextRootId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let root_id = conn .prepare( " @@ -725,9 +741,10 @@ impl Action for GetNextRootId { } impl Action for GetOldestMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -747,9 +764,10 @@ impl Action for GetOldestMsgId { } impl Action for GetNewestMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -769,9 +787,10 @@ impl Action for GetNewestMsgId { } impl Action for GetOlderMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -791,9 +810,10 @@ impl Action for GetOlderMsgId { } } impl Action for GetNewerMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -814,9 +834,10 @@ impl Action for GetNewerMsgId { } impl Action for GetOldestUnseenMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -837,9 +858,10 @@ impl Action for GetOldestUnseenMsgId { } impl Action for GetNewestUnseenMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -860,9 +882,10 @@ impl Action for GetNewestUnseenMsgId { } impl Action for GetOlderUnseenMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -884,9 +907,10 @@ impl Action for GetOlderUnseenMsgId { } impl Action for GetNewerUnseenMsgId { - type Result = Option; + type Output = Option; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let msg_id = conn .prepare( " @@ -908,9 +932,10 @@ impl Action for GetNewerUnseenMsgId { } impl Action for GetUnseenMsgsCount { - type Result = usize; + type Output = usize; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { let amount = conn .prepare( " @@ -927,9 +952,10 @@ impl Action for GetUnseenMsgsCount { } impl Action for SetSeen { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { conn.execute( " UPDATE euph_msgs @@ -944,9 +970,10 @@ impl Action for SetSeen { } impl Action for SetOlderSeen { - type Result = (); + type Output = (); + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { conn.execute( " UPDATE euph_msgs @@ -962,9 +989,10 @@ impl Action for SetOlderSeen { } impl Action for GetChunkAfter { - type Result = Vec; + type Output = Vec; + type Error = rusqlite::Error; - fn run(self, conn: &mut Connection) -> rusqlite::Result { + fn run(self, conn: &mut Connection) -> Result { fn row2msg(row: &Row<'_>) -> rusqlite::Result { Ok(Message { id: MessageId(row.get::<_, WSnowflake>(0)?.0), @@ -1023,7 +1051,7 @@ impl Action for GetChunkAfter { #[async_trait] impl MsgStore for EuphRoomVault { - type Error = vault::tokio::Error; + type Error = vault::tokio::Error; async fn path(&self, id: &MessageId) -> Result, Self::Error> { self.path(*id).await