Rename modules to names not used within std
This commit is contained in:
		
							parent
							
								
									069f5cc128
								
							
						
					
					
						commit
						c2297c9937
					
				
							
								
								
									
										26
									
								
								src/kot.rs
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/kot.rs
									
									
									
									
									
								
							@ -7,11 +7,11 @@
 | 
				
			|||||||
##############################################################################*/
 | 
					##############################################################################*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::path::PathBuf;
 | 
					use std::path::PathBuf;
 | 
				
			||||||
use crate::kot::fs::check_collisions;
 | 
					use crate::kot::kfs::check_collisions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod cli;
 | 
					pub mod kcli;
 | 
				
			||||||
pub mod fs;
 | 
					pub mod kfs;
 | 
				
			||||||
pub mod io;
 | 
					pub mod kio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Result alias to return result with Error of various types
 | 
					/// Result alias to return result with Error of various types
 | 
				
			||||||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
 | 
					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
 | 
					/// Creates symbolic links to the configurations we're installing
 | 
				
			||||||
// TODO: On error, revert to last good state
 | 
					// TODO: On error, revert to last good state
 | 
				
			||||||
// TODO: User script to execute after installing configs successfully
 | 
					// 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
 | 
					    // Get the configurations and their target installation paths
 | 
				
			||||||
    // + Checks for conflicts and prompts user to abort or continue
 | 
					    // + 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
 | 
					    // Check if there are any existing files in the install directory that are also within the dotfiles to install
 | 
				
			||||||
    handle_collisions(&args, &config_map)?;
 | 
					    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
 | 
					/// Handles collisions between existing files and dotfiles we're installing
 | 
				
			||||||
fn handle_collisions(args : & cli::Cli,
 | 
					fn handle_collisions(args : & kcli::Cli,
 | 
				
			||||||
                     config_map : & fs::HashMap<PathBuf, PathBuf>) -> Result<()> {
 | 
					                     config_map : & kfs::HashMap<PathBuf, PathBuf>) -> Result<()> {
 | 
				
			||||||
    // Check if we found any collisions in the configurations
 | 
					    // Check if we found any collisions in the configurations
 | 
				
			||||||
    match check_collisions(&config_map) {
 | 
					    match check_collisions(&config_map) {
 | 
				
			||||||
        None => {
 | 
					        None => {
 | 
				
			||||||
@ -76,7 +76,7 @@ fn handle_collisions(args : & cli::Cli,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            // If we abort, exit; If we continue, back up the configs
 | 
					            // 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?
 | 
					            // 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(()),
 | 
					                true => return Ok(()),
 | 
				
			||||||
                false => {
 | 
					                false => {
 | 
				
			||||||
                    // Backup each conflicting config at the install location
 | 
					                    // 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
 | 
					// + Backup directory location is specified by CLI --backup-dir
 | 
				
			||||||
// TODO: .kotignore in dotfiles repo to specify files to not install / backup
 | 
					// 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?
 | 
					// 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();
 | 
					    let mut backup_path = args.backup_dir.to_owned();
 | 
				
			||||||
    backup_path.push(config_path.file_name().unwrap());
 | 
					    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() {
 | 
					    match config_path.is_dir() {
 | 
				
			||||||
        true => {
 | 
					        true => {
 | 
				
			||||||
            // Copy directory with recursion using move_dir() wrapper function
 | 
					            // 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.copy_inside = true;
 | 
				
			||||||
            options.overwrite = args.force;
 | 
					            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()) {
 | 
					                .map_err(|e| e.into()) {
 | 
				
			||||||
                return Err(e)
 | 
					                return Err(e)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -116,7 +116,7 @@ fn backup_config(config_path: & fs::PathBuf, args: & cli::Cli) -> Result<()> {
 | 
				
			|||||||
            // Copy single configuration file
 | 
					            // Copy single configuration file
 | 
				
			||||||
            let mut options = fs_extra::file::CopyOptions::new();
 | 
					            let mut options = fs_extra::file::CopyOptions::new();
 | 
				
			||||||
            options.overwrite = args.force;
 | 
					            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()) {
 | 
					                .map_err(|e| e.into()) {
 | 
				
			||||||
                return Err(e)
 | 
					                return Err(e)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -104,7 +104,7 @@ impl Cli {
 | 
				
			|||||||
            let mut temp_path = Path::new("/tmp/").to_path_buf();
 | 
					            let mut temp_path = Path::new("/tmp/").to_path_buf();
 | 
				
			||||||
            temp_path.push(self.backup_dir.file_name().unwrap());
 | 
					            temp_path.push(self.backup_dir.file_name().unwrap());
 | 
				
			||||||
            // Move the old backups to /tmp/ and create a new empty backup directory
 | 
					            // 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)?;
 | 
					            std::fs::create_dir_all(&self.backup_dir)?;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -22,7 +22,7 @@ use std::fs;
 | 
				
			|||||||
/// Initialize and return a HashMap<config_dir, config_install_location>
 | 
					/// Initialize and return a HashMap<config_dir, config_install_location>
 | 
				
			||||||
/// + Later used to check each install location for conflicts before installing
 | 
					/// + Later used to check each install location for conflicts before installing
 | 
				
			||||||
/// + This function does not create or modify any files or directories
 | 
					/// + 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();
 | 
					    let mut config_map = HashMap::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Local variable for the installation directory as an absolute path
 | 
					    // Local variable for the installation directory as an absolute path
 | 
				
			||||||
@ -18,7 +18,7 @@ mod kot;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
fn main() -> kot::Result<()> {
 | 
					fn main() -> kot::Result<()> {
 | 
				
			||||||
    // Call augmented kot::cli::from_args() to parse CLI arguments
 | 
					    // 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
 | 
					    // At this point all paths exist and have been converted to absolute paths
 | 
				
			||||||
    println!("args: {:?}\n", args);
 | 
					    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
 | 
					            // 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
 | 
					            // TODO: Isolate this to limit error scope to backup related functions
 | 
				
			||||||
            if args.force {
 | 
					            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());
 | 
					                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)?;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        _ => ()
 | 
					        _ => ()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user