Rename modules to names not used within std

This commit is contained in:
Shaun Reed 2021-12-29 14:54:03 -05:00
parent 069f5cc128
commit c2297c9937
5 changed files with 18 additions and 18 deletions

View File

@ -7,11 +7,11 @@
##############################################################################*/
use std::path::PathBuf;
use crate::kot::fs::check_collisions;
use crate::kot::kfs::check_collisions;
pub mod cli;
pub mod fs;
pub mod io;
pub mod kcli;
pub mod kfs;
pub mod kio;
/// Result alias to return result with Error of various types
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
@ -25,10 +25,10 @@ pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
/// Creates symbolic links to the configurations we're installing
// TODO: On error, revert to last good state
// TODO: User script to execute after installing configs successfully
pub fn install_configs(args: & cli::Cli) -> Result<()> {
pub fn install_configs(args: & kcli::Cli) -> Result<()> {
// Get the configurations and their target installation paths
// + Checks for conflicts and prompts user to abort or continue
let config_map = fs::get_target_paths(&args)?;
let config_map = kfs::get_target_paths(&args)?;
// Check if there are any existing files in the install directory that are also within the dotfiles to install
handle_collisions(&args, &config_map)?;
@ -57,8 +57,8 @@ pub fn install_configs(args: & cli::Cli) -> Result<()> {
}
/// Handles collisions between existing files and dotfiles we're installing
fn handle_collisions(args : & cli::Cli,
config_map : & fs::HashMap<PathBuf, PathBuf>) -> Result<()> {
fn handle_collisions(args : & kcli::Cli,
config_map : & kfs::HashMap<PathBuf, PathBuf>) -> Result<()> {
// Check if we found any collisions in the configurations
match check_collisions(&config_map) {
None => {
@ -76,7 +76,7 @@ fn handle_collisions(args : & cli::Cli,
// If we abort, exit; If we continue, back up the configs
// TODO: Group this in with the --force flag?; Or make a new --adopt flag?
match io::prompt(msg) {
match kio::prompt(msg) {
true => return Ok(()),
false => {
// Backup each conflicting config at the install location
@ -96,7 +96,7 @@ fn handle_collisions(args : & cli::Cli,
// + Backup directory location is specified by CLI --backup-dir
// TODO: .kotignore in dotfiles repo to specify files to not install / backup
// TODO: .kotrc in dotfiles repo or home dir to set backup-dir and install-dir?
fn backup_config(config_path: & fs::PathBuf, args: & cli::Cli) -> Result<()> {
fn backup_config(config_path: & kfs::PathBuf, args: & kcli::Cli) -> Result<()> {
let mut backup_path = args.backup_dir.to_owned();
backup_path.push(config_path.file_name().unwrap());
@ -104,10 +104,10 @@ fn backup_config(config_path: & fs::PathBuf, args: & cli::Cli) -> Result<()> {
match config_path.is_dir() {
true => {
// Copy directory with recursion using move_dir() wrapper function
let mut options = fs::dir::CopyOptions::new();
let mut options = kfs::dir::CopyOptions::new();
options.copy_inside = true;
options.overwrite = args.force;
if let Err(e) = fs::move_dir(config_path, &backup_path, Some(&options))
if let Err(e) = kfs::move_dir(config_path, &backup_path, Some(&options))
.map_err(|e| e.into()) {
return Err(e)
}
@ -116,7 +116,7 @@ fn backup_config(config_path: & fs::PathBuf, args: & cli::Cli) -> Result<()> {
// Copy single configuration file
let mut options = fs_extra::file::CopyOptions::new();
options.overwrite = args.force;
if let Err(e) = fs::move_file(config_path, &backup_path, Some(&options))
if let Err(e) = kfs::move_file(config_path, &backup_path, Some(&options))
.map_err(|e| e.into()) {
return Err(e)
}

View File

@ -104,7 +104,7 @@ impl Cli {
let mut temp_path = Path::new("/tmp/").to_path_buf();
temp_path.push(self.backup_dir.file_name().unwrap());
// Move the old backups to /tmp/ and create a new empty backup directory
super::fs::move_dir( &self.backup_dir, &temp_path, Some(&options))?;
super::kfs::move_dir(&self.backup_dir, &temp_path, Some(&options))?;
std::fs::create_dir_all(&self.backup_dir)?;
}

View File

@ -22,7 +22,7 @@ use std::fs;
/// Initialize and return a HashMap<config_dir, config_install_location>
/// + Later used to check each install location for conflicts before installing
/// + This function does not create or modify any files or directories
pub fn get_target_paths(args: & super::cli::Cli) -> super::Result<HashMap<PathBuf, PathBuf>> {
pub fn get_target_paths(args: & super::kcli::Cli) -> super::Result<HashMap<PathBuf, PathBuf>> {
let mut config_map = HashMap::new();
// Local variable for the installation directory as an absolute path

View File

@ -18,7 +18,7 @@ mod kot;
fn main() -> kot::Result<()> {
// Call augmented kot::cli::from_args() to parse CLI arguments
let args = kot::cli::from_args()?;
let args = kot::kcli::from_args()?;
// At this point all paths exist and have been converted to absolute paths
println!("args: {:?}\n", args);
@ -34,9 +34,9 @@ fn main() -> kot::Result<()> {
// If we were forcing a backup and met some error, revert backups to last good state
// TODO: Isolate this to limit error scope to backup related functions
if args.force {
let mut temp_path : PathBuf = kot::fs::Path::new("/tmp/").to_path_buf();
let mut temp_path : PathBuf = kot::kfs::Path::new("/tmp/").to_path_buf();
temp_path.push(args.backup_dir.file_name().unwrap());
kot::fs::move_dir(&temp_path, &args.backup_dir, None)?;
kot::kfs::move_dir(&temp_path, &args.backup_dir, None)?;
}
},
_ => ()