fn remove_file(current_path: &mut PathBuf, base_path: &Path, path: &str) -> anyhow::Result<()> {
    // Add path to list of items to remove
    let mut vec = Vec::new();
    vec.push(current_path.clone());

    // If current folder has nothing left after deleting the `path`
    // Try to remove parent folders until root of password store
    while current_path.pop() {
        // Stop when we are at the root of password store
        if current_path.as_path() == base_path {
            break;
        }

        // Try to read contents of directory
        if let Ok(contents) = current_path.read_dir() {
            // If there's only one element left (the one we are deleting)
            if contents.count() == 1 {
                vec.push(current_path.clone());
            }
        }
    }

    // Delete all the elements
    fs_extra::remove_items(&vec)?;

    println!("Removed `{}` from password store", path);

    Ok(())
}
/// Remove file `current_path` and folders if they are empty
Remove file `current_path` and folders if they are empty
Remove file ` current_path ` and folders if they are empty
fn remove_file(current_path: &mut PathBuf, base_path: &Path, path: &str) -> anyhow::Result<()> {
    // Add path to list of items to remove
    let mut vec = Vec::new();
    vec.push(current_path.clone());
    // If current folder has nothing left after deleting the `path`
    // Try to remove parent folders until root of password store
    while current_path.pop() {
        // Stop when we are at the root of password store
        if current_path.as_path() == base_path {
            break;
        }
        // Try to read contents of directory
        if let Ok(contents) = current_path.read_dir() {
            // If there's only one element left (the one we are deleting)
            if contents.count() == 1 {
                vec.push(current_path.clone());
            }
        }
    }
    // Delete all the elements
    fs_extra::remove_items(&vec)?;
    println!("Removed `{}` from password store", path);
    Ok(())
}
fn remove_file ( current_path : & mut PathBuf , base_path : & Path , path : & str ) -> anyhow :: Result < ( ) > { // Add path to list of items to remove let mut vec = Vec :: new ( ) ; vec . push ( current_path . clone ( ) ) ; // If current folder has nothing left after deleting the `path` // Try to remove parent folders until root of password store while current_path . pop ( ) { // Stop when we are at the root of password store if current_path . as_path ( ) == base_path { break ; } // Try to read contents of directory if let Ok ( contents ) = current_path . read_dir ( ) { // If there's only one element left (the one we are deleting) if contents . count ( ) == 1 { vec . push ( current_path . clone ( ) ) ; } } } // Delete all the elements fs_extra :: remove_items ( & vec ) ? ; println ! ( " " path ) ; Ok ( ( ) ) }
Remove file `current_path` and folders if they are empty
Remove file ` current_path ` and folders if they are empty
current_path
&mut PathBuf
base_path
&Path
path
&str
current_path
&mut PathBuf
base_path
&Path
path
&str