notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 8043d86bf252f53c97470eeb1f641aaa7d083d27
parent ebfa9e4450ec799e9e2c28b20af551805635bf98
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 15 Nov 2024 11:56:34 -0800

arg: fix broken dbpath argument, add test

I broke dbpath, lets fix that and add a test so it doesn't happen again

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/app.rs | 9+++++----
Msrc/args.rs | 26++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -392,10 +392,11 @@ impl Damus { .datapath .unwrap_or(data_path.as_ref().to_str().expect("db path ok").to_string()); let path = DataPath::new(&data_path); - let dbpath_ = path.path(DataPathType::Db); - let dbpath = dbpath_.to_str().unwrap(); + let dbpath_str = parsed_args + .dbpath + .unwrap_or_else(|| path.path(DataPathType::Db).to_str().unwrap().to_string()); - let _ = std::fs::create_dir_all(dbpath); + let _ = std::fs::create_dir_all(&dbpath_str); let imgcache_dir = path.path(DataPathType::Cache).join(ImageCache::rel_dir()); let _ = std::fs::create_dir_all(imgcache_dir.clone()); @@ -453,7 +454,7 @@ impl Damus { .get_selected_account() .as_ref() .map(|a| a.pubkey.bytes()); - let ndb = Ndb::new(dbpath, &config).expect("ndb"); + let ndb = Ndb::new(&dbpath_str, &config).expect("ndb"); let mut columns = if parsed_args.columns.is_empty() { if let Some(serializable_columns) = storage::load_columns(&path) { diff --git a/src/args.rs b/src/args.rs @@ -265,6 +265,32 @@ mod tests { std::fs::remove_dir_all(path); } + /// Ensure dbpath actually sets the dbpath correctly. + #[tokio::test] + async fn test_dbpath() { + let datapath = create_tmp_dir(); + let dbpath = create_tmp_dir(); + let args = vec![ + "--datapath", + &datapath.to_str().unwrap(), + "--dbpath", + &dbpath.to_str().unwrap(), + ] + .iter() + .map(|s| s.to_string()) + .collect(); + + let ctx = egui::Context::default(); + let app = Damus::new(&ctx, &datapath, args); + + assert!(Path::new(&dbpath.join("data.mdb")).exists()); + assert!(Path::new(&dbpath.join("lock.mdb")).exists()); + assert!(!Path::new(&datapath.join("db")).exists()); + + rmrf(datapath); + rmrf(dbpath); + } + #[tokio::test] async fn test_column_args() { let tmpdir = create_tmp_dir();