diff options
author | Vika <vika@fireburn.ru> | 2022-05-10 01:37:03 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2022-05-10 01:37:03 +0300 |
commit | d38c4ac55ea68ae6dd0262ddd95150b7d46bf93b (patch) | |
tree | 5947358d9611d6deff8e9aeed139996c62220277 | |
parent | 1648c476a1d3d8f56daf09840baaddeb5967c5ed (diff) | |
download | kittybox-d38c4ac55ea68ae6dd0262ddd95150b7d46bf93b.tar.zst |
FileStorage: code cleanup
-rw-r--r-- | src/database/file/mod.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index 64d9564..031527e 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -171,12 +171,11 @@ fn modify_post(post: &serde_json::Value, update: &serde_json::Value) -> Result<s } for (k, v) in remove_values { let k = &k; - let props; - if k == "children" { - props = &mut post; + let props = if k == "children" { + &mut post } else { - props = &mut post["properties"]; - } + &mut post["properties"] + }; v.iter().for_each(|v| { if let Some(vec) = props[k].as_array_mut() { if let Some(index) = vec.iter().position(|w| w == v) { @@ -186,12 +185,11 @@ fn modify_post(post: &serde_json::Value, update: &serde_json::Value) -> Result<s }); } for (k, v) in add_keys { - let props; - if k == "children" { - props = &mut post; + let props = if k == "children" { + &mut post } else { - props = &mut post["properties"]; - } + &mut post["properties"] + }; let k = &k; if let Some(prop) = props[k].as_array_mut() { if k == "children" { @@ -357,10 +355,7 @@ impl Storage for FileStorage { })?; let relative = path_relative_from(&orig, basedir).unwrap(); println!("{:?} - {:?} = {:?}", &orig, &basedir, &relative); - #[cfg(unix)] tokio::fs::symlink(relative, link).await?; - #[cfg(not(unix))] - compile_error!("Don't know how to create symlinks on your OS"); } } } @@ -603,7 +598,9 @@ impl Storage for FileStorage { } Err(err) => if err.kind() == IOErrorKind::NotFound { HashMap::default() - } else { Err(err)? } + } else { + return Err(err.into()) + } }; settings.insert(setting, value); tempfile.write_all(serde_json::to_string(&settings)?.as_bytes()).await?; |