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
This commit is contained in:
Aaryamann Challani 2023-06-07 16:58:39 +05:30 committed by GitHub
parent ecd056884c
commit 9cc86e526e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -58,9 +58,9 @@ impl FromStr for PmtreeConfig {
fn from_str(s: &str) -> Result<Self> {
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()))