mirror of https://github.com/vacp2p/zerokit.git
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:
parent
ecd056884c
commit
9cc86e526e
|
@ -58,9 +58,9 @@ impl FromStr for PmtreeConfig {
|
||||||
fn from_str(s: &str) -> Result<Self> {
|
fn from_str(s: &str) -> Result<Self> {
|
||||||
let config: Value = serde_json::from_str(s)?;
|
let config: Value = serde_json::from_str(s)?;
|
||||||
|
|
||||||
let temporary = config["temporary"].as_bool();
|
|
||||||
let path = config["path"].as_str();
|
let path = config["path"].as_str();
|
||||||
let path = path.map(PathBuf::from);
|
let path = path.map(PathBuf::from);
|
||||||
|
let temporary = config["temporary"].as_bool();
|
||||||
let cache_capacity = config["cache_capacity"].as_u64();
|
let cache_capacity = config["cache_capacity"].as_u64();
|
||||||
let flush_every_ms = config["flush_every_ms"].as_u64();
|
let flush_every_ms = config["flush_every_ms"].as_u64();
|
||||||
let mode = match config["mode"].as_str() {
|
let mode = match config["mode"].as_str() {
|
||||||
|
@ -70,6 +70,17 @@ impl FromStr for PmtreeConfig {
|
||||||
};
|
};
|
||||||
let use_compression = config["use_compression"].as_bool();
|
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()
|
let config = pm_tree::Config::new()
|
||||||
.temporary(temporary.unwrap_or(get_tmp()))
|
.temporary(temporary.unwrap_or(get_tmp()))
|
||||||
.path(path.unwrap_or(get_tmp_path()))
|
.path(path.unwrap_or(get_tmp_path()))
|
||||||
|
|
Loading…
Reference in New Issue