diff --git a/src/profile/identity/gemini.rs b/src/profile/identity/gemini.rs index 9369fd0d..fec3d136 100644 --- a/src/profile/identity/gemini.rs +++ b/src/profile/identity/gemini.rs @@ -87,8 +87,10 @@ impl Gemini { /// Create new `Memory` index from `Database` for `Self` pub fn index(&self) -> Result<(), Error> { - // Cleanup previous records - self.memory.clear(); + // Clear previous records + if let Err(reason) = self.memory.clear() { + return Err(Error::MemoryClear(reason)); + } // Build new index match self.database.records() { @@ -101,7 +103,8 @@ impl Gemini { } Err(reason) => return Err(Error::DatabaseIndex(reason)), }; - Ok(()) // @TODO + + Ok(()) } } diff --git a/src/profile/identity/gemini/auth.rs b/src/profile/identity/gemini/auth.rs index 3e2955f0..9e53342e 100644 --- a/src/profile/identity/gemini/auth.rs +++ b/src/profile/identity/gemini/auth.rs @@ -84,7 +84,9 @@ impl Auth { /// Create new `Memory` index from `Database` for `Self` pub fn index(&self) -> Result<(), Error> { // Clear previous records - self.memory.clear(); + if let Err(reason) = self.memory.clear() { + return Err(Error::MemoryClear(reason)); + } // Build new index match self.database.records(None) { @@ -100,6 +102,7 @@ impl Auth { } Err(reason) => return Err(Error::DatabaseIndex(reason)), } + Ok(()) } } diff --git a/src/profile/identity/gemini/auth/error.rs b/src/profile/identity/gemini/auth/error.rs index a305e8a8..4e29e02a 100644 --- a/src/profile/identity/gemini/auth/error.rs +++ b/src/profile/identity/gemini/auth/error.rs @@ -4,5 +4,6 @@ pub enum Error { DatabaseRecordCreate(i64, String, sqlite::Error), DatabaseRecordDelete(i64, sqlite::Error), DatabaseRecordsRead(String, sqlite::Error), + MemoryClear(super::memory::Error), MemoryIndex(super::memory::Error), } diff --git a/src/profile/identity/gemini/auth/memory.rs b/src/profile/identity/gemini/auth/memory.rs index 374d6dc1..ecf4a260 100644 --- a/src/profile/identity/gemini/auth/memory.rs +++ b/src/profile/identity/gemini/auth/memory.rs @@ -1,4 +1,4 @@ -mod error; +pub mod error; pub use error::Error; use std::{cell::RefCell, collections::HashMap}; @@ -34,8 +34,14 @@ impl Memory { } /// Cleanup index - pub fn clear(&self) { - self.index.borrow_mut().clear() + pub fn clear(&self) -> Result<(), Error> { + let mut index = self.index.borrow_mut(); + index.clear(); + if index.is_empty() { + Ok(()) + } else { + Err(Error::Clear) + } } /// Get `profile_identity_gemini_id` vector match given `request` diff --git a/src/profile/identity/gemini/auth/memory/error.rs b/src/profile/identity/gemini/auth/memory/error.rs index 0952f998..a9689656 100644 --- a/src/profile/identity/gemini/auth/memory/error.rs +++ b/src/profile/identity/gemini/auth/memory/error.rs @@ -1,4 +1,5 @@ #[derive(Debug)] pub enum Error { + Clear, Overwrite(i64), } diff --git a/src/profile/identity/gemini/error.rs b/src/profile/identity/gemini/error.rs index bf9285cc..2030e33f 100644 --- a/src/profile/identity/gemini/error.rs +++ b/src/profile/identity/gemini/error.rs @@ -3,6 +3,7 @@ pub enum Error { AuthInit(super::auth::Error), DatabaseIndex(sqlite::Error), DatabaseRecordCreate(sqlite::Error), + MemoryClear(super::memory::Error), MemoryIndex(i64), Certificate(Box), } diff --git a/src/profile/identity/gemini/memory.rs b/src/profile/identity/gemini/memory.rs index 8ef10dc8..aa3709e6 100644 --- a/src/profile/identity/gemini/memory.rs +++ b/src/profile/identity/gemini/memory.rs @@ -1,5 +1,5 @@ -mod error; -use error::Error; +pub mod error; +pub use error::Error; use std::{cell::RefCell, collections::HashMap}; @@ -38,7 +38,13 @@ impl Memory { } /// Cleanup index - pub fn clear(&self) { - self.index.borrow_mut().clear() + pub fn clear(&self) -> Result<(), Error> { + let mut index = self.index.borrow_mut(); + index.clear(); + if index.is_empty() { + Ok(()) + } else { + Err(Error::Clear) + } } } diff --git a/src/profile/identity/gemini/memory/error.rs b/src/profile/identity/gemini/memory/error.rs index 5efe607f..3187386b 100644 --- a/src/profile/identity/gemini/memory/error.rs +++ b/src/profile/identity/gemini/memory/error.rs @@ -1,5 +1,6 @@ #[derive(Debug)] pub enum Error { + Clear, NotFound(i64), Overwrite(String), }