Просмотр исходного кода

wallet: Create parent path to database if necessary.

parazyd 4 лет назад
Родитель
Сommit
f019220bcf
2 измененных файлов с 14 добавлено и 2 удалено
  1. 7 1
      src/wallet/cashierdb.rs
  2. 7 1
      src/wallet/walletdb.rs

+ 7 - 1
src/wallet/cashierdb.rs

@@ -1,4 +1,4 @@
-use std::str::FromStr;
+use std::{fs::create_dir_all, path::Path, str::FromStr};
 
 use async_std::sync::Arc;
 use log::{debug, error, info};
@@ -52,6 +52,12 @@ impl CashierDb {
             return Err(Error::from(ClientFailed::EmptyPassword))
         }
 
+        let p = Path::new(path.strip_prefix("sqlite://").unwrap());
+        if let Some(dirname) = p.parent() {
+            debug!("Creating path to database: {}", dirname.display());
+            create_dir_all(&dirname)?;
+        }
+
         let connect_opts = SqliteConnectOptions::from_str(path)?
             .pragma("key", password)
             .create_if_missing(true)

+ 7 - 1
src/wallet/walletdb.rs

@@ -1,4 +1,4 @@
-use std::str::FromStr;
+use std::{fs::create_dir_all, path::Path, str::FromStr};
 
 use async_std::sync::Arc;
 use log::{debug, error, info};
@@ -51,6 +51,12 @@ impl WalletDb {
             return Err(Error::from(ClientFailed::EmptyPassword))
         }
 
+        let p = Path::new(path.strip_prefix("sqlite://").unwrap());
+        if let Some(dirname) = p.parent() {
+            debug!("Creating path to database: {}", dirname.display());
+            create_dir_all(&dirname)?;
+        }
+
         let connect_opts = SqliteConnectOptions::from_str(path)?
             .pragma("key", password)
             .create_if_missing(true)