From f9a60bf48b14a63b81ce66ede6bf898538b48ef2 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 20 Mar 2024 00:23:46 -0400 Subject: [PATCH] make database_backup_path a PathBuf Signed-off-by: strawberry --- src/config/mod.rs | 6 +++--- src/database/abstraction/rocksdb.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index d8344982..604cb8d8 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -42,7 +42,7 @@ pub struct Config { #[serde(default = "default_database_backend")] pub database_backend: String, pub database_path: PathBuf, - pub database_backup_path: Option, + pub database_backup_path: Option, #[serde(default = "default_database_backups_to_keep")] pub database_backups_to_keep: i16, #[serde(default = "default_db_cache_capacity_mb")] @@ -257,8 +257,8 @@ impl fmt::Display for Config { ("Database path", &self.database_path.to_string_lossy()), ( "Database backup path", - match self.database_backup_path.as_ref() { - Some(path) => path, + match &self.database_backup_path { + Some(path) => path.to_str().unwrap(), None => "", }, ), diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 22f422fb..5398de71 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -225,7 +225,7 @@ impl KeyValueDatabaseEngine for Arc { fn backup(&self) -> Result<(), Box> { let path = self.config.database_backup_path.as_ref(); - if path.is_none() || path.is_some_and(String::is_empty) { + if path.is_none() || path.is_some_and(|path| path.as_os_str().is_empty()) { return Ok(()); } @@ -260,8 +260,10 @@ impl KeyValueDatabaseEngine for Arc { fn backup_list(&self) -> Result { let path = self.config.database_backup_path.as_ref(); - if path.is_none() || path.is_some_and(String::is_empty) { - return Ok("Configure database_backup_path to enable backups".to_owned()); + if path.is_none() || path.is_some_and(|path| path.as_os_str().is_empty()) { + return Ok( + "Configure database_backup_path to enable backups, or the path specified is not valid".to_owned(), + ); } let mut res = String::new();