From c2297c99372a780935074b25b9b2ed860d1194d6 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Wed, 29 Dec 2021 14:54:03 -0500 Subject: [PATCH] Rename modules to names not used within std --- src/kot.rs | 26 +++++++++++++------------- src/kot/{cli.rs => kcli.rs} | 2 +- src/kot/{fs.rs => kfs.rs} | 2 +- src/kot/{io.rs => kio.rs} | 0 src/main.rs | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) rename src/kot/{cli.rs => kcli.rs} (98%) rename src/kot/{fs.rs => kfs.rs} (97%) rename src/kot/{io.rs => kio.rs} (100%) diff --git a/src/kot.rs b/src/kot.rs index 1072b9d..974f496 100644 --- a/src/kot.rs +++ b/src/kot.rs @@ -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 = std::result::Result>; @@ -25,10 +25,10 @@ pub type Result = std::result::Result>; /// 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) -> Result<()> { +fn handle_collisions(args : & kcli::Cli, + config_map : & kfs::HashMap) -> 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) } diff --git a/src/kot/cli.rs b/src/kot/kcli.rs similarity index 98% rename from src/kot/cli.rs rename to src/kot/kcli.rs index 539818f..8422245 100644 --- a/src/kot/cli.rs +++ b/src/kot/kcli.rs @@ -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)?; } diff --git a/src/kot/fs.rs b/src/kot/kfs.rs similarity index 97% rename from src/kot/fs.rs rename to src/kot/kfs.rs index 86b59b6..07bbf80 100644 --- a/src/kot/fs.rs +++ b/src/kot/kfs.rs @@ -22,7 +22,7 @@ use std::fs; /// Initialize and return a HashMap /// + 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> { +pub fn get_target_paths(args: & super::kcli::Cli) -> super::Result> { let mut config_map = HashMap::new(); // Local variable for the installation directory as an absolute path diff --git a/src/kot/io.rs b/src/kot/kio.rs similarity index 100% rename from src/kot/io.rs rename to src/kot/kio.rs diff --git a/src/main.rs b/src/main.rs index 551bc82..8386bab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)?; } }, _ => ()