use std::{
io::{self,ErrorKind,Write},
fs,
path::PathBuf,
};
use copy_dir::copy_dir;
use crate::{resolve_home,Config,Entry};
#[derive(Debug, PartialEq, Eq)]
enum ConflictOption {
Remove,
Rename,
Skip,
}
fn remove_ambiguous(path: &PathBuf) -> io::Result<()> {
if path.is_dir() {
fs::remove_dir_all(&path)?;
} else {
fs::remove_file(&path)?;
}
Ok(())
}
fn rename_conflict(path: &PathBuf) -> io::Result<()> {
let rename_path = path.with_extension("old");
if rename_path.try_exists()? {
remove_ambiguous(&rename_path)?;
}
fs::rename(&path, &rename_path)?;
println!("Old config renamed to {}.", rename_path.file_name().unwrap().to_str().unwrap());
Ok(())
}
fn remove_existing(name: &str, path: &PathBuf) -> io::Result