1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use std::{path::Path, fs}; use crate::{get_files, Result, get_dotfiles_path, ok, warn, is_even, copy_dir}; pub fn link(reverse: bool) -> Result<()> { let couples = get_files::get_files()?; for (from, to) in couples { let mut to = format!("{}/{}", get_dotfiles_path(), to).replace("//", "/"); let mut from = from; let temp = to.clone(); if reverse { to = from.clone(); from = temp; } if is_even(&from, &to)? { ok!(from, " and ", to, " won't be updated.") } else { if Path::new(&to).is_dir() { fs::remove_dir_all(&to)?; } else if Path::new(&to).is_file() { fs::remove_file(&to)?; } if Path::new(&from).is_dir() { copy_dir(&from, &to)?; } else if Path::new(&from).is_file() { fs::copy(&from, &to)?; } else { warn!(from, " does not exist. Skipping entry."); continue; } ok!("Sucessfully", { if reverse { " installed " } else { " linked " } }, from, " to ", to, "."); } } Ok(()) }