From 9cc86e526ee0b34b20e4110dc3e4fded03a046d2 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 7 Jun 2023 16:58:39 +0530 Subject: [PATCH] fix(rln): error out when temporary=true and path is exists (#176) * fix(rln): error out when temporary=true and path is exists * fix(rln): should error out when temp=true and path exists * fix(rln): clippy --- rln/src/pm_tree_adapter.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rln/src/pm_tree_adapter.rs b/rln/src/pm_tree_adapter.rs index 10cd433..40f13f8 100644 --- a/rln/src/pm_tree_adapter.rs +++ b/rln/src/pm_tree_adapter.rs @@ -58,9 +58,9 @@ impl FromStr for PmtreeConfig { fn from_str(s: &str) -> Result { let config: Value = serde_json::from_str(s)?; - let temporary = config["temporary"].as_bool(); let path = config["path"].as_str(); let path = path.map(PathBuf::from); + let temporary = config["temporary"].as_bool(); let cache_capacity = config["cache_capacity"].as_u64(); let flush_every_ms = config["flush_every_ms"].as_u64(); let mode = match config["mode"].as_str() { @@ -70,6 +70,17 @@ impl FromStr for PmtreeConfig { }; let use_compression = config["use_compression"].as_bool(); + if temporary.is_some() + && path.is_some() + && temporary.unwrap() + && path.as_ref().unwrap().exists() + { + return Err(Report::msg(format!( + "Path {:?} already exists, cannot use temporary", + path.unwrap() + ))); + } + let config = pm_tree::Config::new() .temporary(temporary.unwrap_or(get_tmp())) .path(path.unwrap_or(get_tmp_path()))