Skip to content

Commit 74e9dbe

Browse files
erskingardneryukibtc
authored andcommitted
mls-sqlite-storage: create sqlite parent dirs if needed
1 parent e0a124b commit 74e9dbe

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

crates/nostr-mls-sqlite-storage/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ impl From<refinery::Error> for Error {
4040
}
4141
}
4242

43+
impl From<std::io::Error> for Error {
44+
fn from(e: std::io::Error) -> Self {
45+
Self::Database(format!("IO error: {}", e))
46+
}
47+
}
48+
4349
impl From<Error> for rusqlite::Error {
4450
fn from(err: Error) -> Self {
4551
rusqlite::Error::FromSqlConversionFailure(

crates/nostr-mls-sqlite-storage/src/lib.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ impl NostrMlsSqliteStorage {
7878
where
7979
P: AsRef<Path>,
8080
{
81+
// Ensure parent directory exists
82+
if let Some(parent) = file_path.as_ref().parent() {
83+
std::fs::create_dir_all(parent)?;
84+
}
85+
8186
// Create or open the SQLite database
8287
let mls_connection: Connection = Connection::open(&file_path)?;
8388

@@ -226,20 +231,6 @@ mod tests {
226231
temp_dir.close().unwrap();
227232
}
228233

229-
#[test]
230-
fn test_invalid_path() {
231-
let invalid_path = "/nonexistent/directory/db.sqlite";
232-
let storage = NostrMlsSqliteStorage::new(invalid_path);
233-
assert!(storage.is_err());
234-
235-
if let Err(err) = storage {
236-
match err {
237-
Error::Rusqlite(_) => {} // Expected error type
238-
_ => panic!("Expected Rusqlite error, got {:?}", err),
239-
}
240-
}
241-
}
242-
243234
#[test]
244235
fn test_openmls_storage_access() {
245236
let storage = NostrMlsSqliteStorage::new_in_memory().unwrap();

0 commit comments

Comments
 (0)