pub fn clean(mut hc_dir: PathBuf, setups: Vec<usize>) -> anyhow::Result<()> {
    let existing = load(hc_dir.clone())?;
    let setups_len = setups.len();
    let to_remove: Vec<_> = if setups.is_empty() {
        existing.iter().collect()
    } else {
        setups.into_iter().filter_map(|i| existing.get(i)).collect()
    };
    let to_remove_len = to_remove.len();
    for p in to_remove {
        if p.exists() && p.is_dir() {
            if let Err(e) = std::fs::remove_dir_all(p) {
                tracing::error!("Failed to remove {} because {:?}", p.display(), e);
            }
        }
    }
    if setups_len == 0 || setups_len == to_remove_len {
        hc_dir.push(".hc");
        if hc_dir.exists() {
            std::fs::remove_file(hc_dir)?;
        }
    }
    Ok(())
}
/// Remove setups by their index in the file.
/// You can get the index by calling [`load`].
/// If no setups are passed in then all are deleted.
/// If all setups are deleted the `.hc` file will be removed.
Remove setups by their index in the file.
You can get the index by calling [`load`].
If no setups are passed in then all are deleted.
If all setups are deleted the `.hc` file will be removed.
Remove setups by their index in the file . You can get the index by calling [ ` load ` ] . If no setups are passed in then all are deleted . If all setups are deleted the ` . hc ` file will be removed .
pub fn clean(mut hc_dir: PathBuf, setups: Vec<usize>) -> anyhow::Result<()> {
    let existing = load(hc_dir.clone())?;
    let setups_len = setups.len();
    let to_remove: Vec<_> = if setups.is_empty() {
        existing.iter().collect()
    } else {
        setups.into_iter().filter_map(|i| existing.get(i)).collect()
    };
    let to_remove_len = to_remove.len();
    for p in to_remove {
        if p.exists() && p.is_dir() {
            if let Err(e) = std::fs::remove_dir_all(p) {
                tracing::error!("Failed to remove {} because {:?}", p.display(), e);
            }
        }
    }
    if setups_len == 0 || setups_len == to_remove_len {
        hc_dir.push(".hc");
        if hc_dir.exists() {
            std::fs::remove_file(hc_dir)?;
        }
    }
    Ok(())
}
pub fn clean ( mut hc_dir : PathBuf , setups : Vec < usize > ) -> anyhow :: Result < ( ) > { let existing = load ( hc_dir . clone ( ) ) ? ; let setups_len = setups . len ( ) ; let to_remove : Vec < _ > = if setups . is_empty ( ) { existing . iter ( ) . collect ( ) } else { setups . into_iter ( ) . filter_map ( | i | existing . get ( i ) ) . collect ( ) } ; let to_remove_len = to_remove . len ( ) ; for p in to_remove { if p . exists ( ) && p . is_dir ( ) { if let Err ( e ) = std :: fs :: remove_dir_all ( p ) { tracing :: error ! ( " " p display ( ) e ) ; } } } if setups_len == 0 || setups_len == to_remove_len { hc_dir . push ( " " ) ; if hc_dir . exists ( ) { std :: fs :: remove_file ( hc_dir ) ? ; } } Ok ( ( ) ) }
Remove setups by their index in the file.
Remove setups by their index in the file .
hc_dir
PathBuf
setups
Vec<usize>
hc_dir
PathBuf
setups
Vec<usize>