feat: verbose toggle, info tab, many misc fixes
This commit is contained in:
@ -154,4 +154,23 @@ impl PathStr for PathBuf {
|
||||
|
||||
pub fn bool_to_01(val: bool) -> &'static str {
|
||||
return if val { "1" } else { "0" }
|
||||
}
|
||||
|
||||
// rm -r with checks
|
||||
pub async fn remove_dir_all(path: impl AsRef<Path>) -> Result<()> {
|
||||
let canon = path.as_ref().canonicalize()?;
|
||||
|
||||
if canon.to_string_lossy().len() < 10 {
|
||||
return Err(anyhow!("invalid remove_dir_all target: too short"));
|
||||
}
|
||||
|
||||
if canon.starts_with(data_dir().canonicalize()?)
|
||||
|| canon.starts_with(config_dir().canonicalize()?)
|
||||
|| canon.starts_with(cache_dir().canonicalize()?) {
|
||||
tokio::fs::remove_dir_all(path).await
|
||||
.map_err(|e| anyhow!("invalid remove_dir_all target: {:?}", e))?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("invalid remove_dir_all target: not in a data directory"))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user