From 1c0dee8e60d9c1c989a3712e7d1e19debe981e8a Mon Sep 17 00:00:00 2001 From: diogo464 Date: Wed, 14 Jul 2021 15:07:32 +0100 Subject: Small changes to logging and docs. --- dotup/src/depot.rs | 5 +++-- dotup_cli/src/commands/init.rs | 6 +++--- dotup_cli/src/commands/link.rs | 5 ++++- dotup_cli/src/main.rs | 9 +++------ dotup_cli/src/utils.rs | 28 +++++++++++++++++++++++++++- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/dotup/src/depot.rs b/dotup/src/depot.rs index 6abe29f..4997996 100644 --- a/dotup/src/depot.rs +++ b/dotup/src/depot.rs @@ -70,7 +70,7 @@ impl std::fmt::Display for LinkCreateParams { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "LinkDesc[{} -> {}]", + "{} -> {}", self.origin.display(), self.destination.display() ) @@ -132,6 +132,7 @@ impl Link { &self.destination } + /// Where this link would be installed with the given `install_base`. pub fn install_destination(&self, install_base: &Path) -> std::io::Result { utils::weakly_canonical(install_base.join(self.destination())) } @@ -141,7 +142,7 @@ impl std::fmt::Display for Link { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "Link[{} -> {}]", + "{} -> {}", self.origin().display(), self.destination().display() ) diff --git a/dotup_cli/src/commands/init.rs b/dotup_cli/src/commands/init.rs index 8765dbf..b894924 100644 --- a/dotup_cli/src/commands/init.rs +++ b/dotup_cli/src/commands/init.rs @@ -11,11 +11,11 @@ pub struct Opts {} pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { if !dotup::utils::is_file(&config.archive_path)? { let archive = Archive::default(); - log::info!("Creating archive"); + log::info!("Creating archive at {}", &config.archive_path.display()); utils::write_archive(&config.archive_path, &archive)?; } else { - log::info!( - "Archive file already exists : {}", + log::warn!( + "Archive file already exists : '{}'", config.archive_path.display() ); } diff --git a/dotup_cli/src/commands/link.rs b/dotup_cli/src/commands/link.rs index ed7ee55..4c1ae06 100644 --- a/dotup_cli/src/commands/link.rs +++ b/dotup_cli/src/commands/link.rs @@ -106,9 +106,12 @@ fn link_file( .strip_prefix(base_canonical) .expect("Failed to remove prefix from origin path"); let destination = destination.join(partial); + let origin = origin_canonical + .strip_prefix(depot.base_path()) + .unwrap_or(&origin_canonical); let link_params = LinkCreateParams { - origin: origin_canonical, + origin: origin.to_path_buf(), destination, }; params.push(link_params); diff --git a/dotup_cli/src/main.rs b/dotup_cli/src/main.rs index 05fdcab..d500a7d 100644 --- a/dotup_cli/src/main.rs +++ b/dotup_cli/src/main.rs @@ -38,8 +38,6 @@ struct Opts { /// A level of verbosity, and can be used multiple times /// - /// Level 0 - Warnings (Default) - /// /// Level 1 - Info /// /// Level 2 - Debug @@ -66,15 +64,14 @@ fn main() -> anyhow::Result<()> { if !opts.quiet { let log_level = match opts.verbose { - 0 => "warn", - 1 => "info", - 2 => "debug", + 0 => "info", + 1 => "debug", _ => "trace", }; Logger::try_with_env_or_str(log_level)? .format(flexi_logger::colored_default_format) - //.set_palette("196;208;32;198;15".to_string()) + .set_palette("196;208;32;198;15".to_string()) .start()?; } diff --git a/dotup_cli/src/utils.rs b/dotup_cli/src/utils.rs index fad37ae..d284a22 100644 --- a/dotup_cli/src/utils.rs +++ b/dotup_cli/src/utils.rs @@ -1,4 +1,7 @@ -use std::path::{Path, PathBuf}; +use std::{ + collections::VecDeque, + path::{Path, PathBuf}, +}; use crate::prelude::*; @@ -123,3 +126,26 @@ pub fn collect_link_ids_by_base_paths( .map(|l| l.id()) .collect() } + +/// Returns a list of canonical paths to all the files in `dir`. This includes files in +/// subdirectories. +/// Fails if dir isnt a directory or if there is some other io error. +pub fn collect_files_in_dir(dir: impl Into) -> anyhow::Result> { + let mut paths = Vec::new(); + let mut dirs = VecDeque::new(); + dirs.push_back(dir.into()); + + while let Some(dir) = dirs.pop_front() { + for entry in std::fs::read_dir(dir)? { + let entry = entry?; + let filetype = entry.file_type()?; + if filetype.is_dir() { + dirs.push_back(entry.path()); + } else { + paths.push(entry.path()); + } + } + } + + Ok(paths) +} -- cgit