aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2021-07-14 15:07:32 +0100
committerdiogo464 <[email protected]>2021-07-14 15:07:32 +0100
commit1c0dee8e60d9c1c989a3712e7d1e19debe981e8a (patch)
tree07997fddae442679c90914b2c4abe3c953250838
parent4adc2435da7d58cd34b9f1706b3cea9fb524b946 (diff)
Small changes to logging and docs.
-rw-r--r--dotup/src/depot.rs5
-rw-r--r--dotup_cli/src/commands/init.rs6
-rw-r--r--dotup_cli/src/commands/link.rs5
-rw-r--r--dotup_cli/src/main.rs9
-rw-r--r--dotup_cli/src/utils.rs28
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 {
70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 write!( 71 write!(
72 f, 72 f,
73 "LinkDesc[{} -> {}]", 73 "{} -> {}",
74 self.origin.display(), 74 self.origin.display(),
75 self.destination.display() 75 self.destination.display()
76 ) 76 )
@@ -132,6 +132,7 @@ impl Link {
132 &self.destination 132 &self.destination
133 } 133 }
134 134
135 /// Where this link would be installed with the given `install_base`.
135 pub fn install_destination(&self, install_base: &Path) -> std::io::Result<PathBuf> { 136 pub fn install_destination(&self, install_base: &Path) -> std::io::Result<PathBuf> {
136 utils::weakly_canonical(install_base.join(self.destination())) 137 utils::weakly_canonical(install_base.join(self.destination()))
137 } 138 }
@@ -141,7 +142,7 @@ impl std::fmt::Display for Link {
141 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
142 write!( 143 write!(
143 f, 144 f,
144 "Link[{} -> {}]", 145 "{} -> {}",
145 self.origin().display(), 146 self.origin().display(),
146 self.destination().display() 147 self.destination().display()
147 ) 148 )
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 {}
11pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { 11pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
12 if !dotup::utils::is_file(&config.archive_path)? { 12 if !dotup::utils::is_file(&config.archive_path)? {
13 let archive = Archive::default(); 13 let archive = Archive::default();
14 log::info!("Creating archive"); 14 log::info!("Creating archive at {}", &config.archive_path.display());
15 utils::write_archive(&config.archive_path, &archive)?; 15 utils::write_archive(&config.archive_path, &archive)?;
16 } else { 16 } else {
17 log::info!( 17 log::warn!(
18 "Archive file already exists : {}", 18 "Archive file already exists : '{}'",
19 config.archive_path.display() 19 config.archive_path.display()
20 ); 20 );
21 } 21 }
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(
106 .strip_prefix(base_canonical) 106 .strip_prefix(base_canonical)
107 .expect("Failed to remove prefix from origin path"); 107 .expect("Failed to remove prefix from origin path");
108 let destination = destination.join(partial); 108 let destination = destination.join(partial);
109 let origin = origin_canonical
110 .strip_prefix(depot.base_path())
111 .unwrap_or(&origin_canonical);
109 112
110 let link_params = LinkCreateParams { 113 let link_params = LinkCreateParams {
111 origin: origin_canonical, 114 origin: origin.to_path_buf(),
112 destination, 115 destination,
113 }; 116 };
114 params.push(link_params); 117 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 {
38 38
39 /// A level of verbosity, and can be used multiple times 39 /// A level of verbosity, and can be used multiple times
40 /// 40 ///
41 /// Level 0 - Warnings (Default)
42 ///
43 /// Level 1 - Info 41 /// Level 1 - Info
44 /// 42 ///
45 /// Level 2 - Debug 43 /// Level 2 - Debug
@@ -66,15 +64,14 @@ fn main() -> anyhow::Result<()> {
66 64
67 if !opts.quiet { 65 if !opts.quiet {
68 let log_level = match opts.verbose { 66 let log_level = match opts.verbose {
69 0 => "warn", 67 0 => "info",
70 1 => "info", 68 1 => "debug",
71 2 => "debug",
72 _ => "trace", 69 _ => "trace",
73 }; 70 };
74 71
75 Logger::try_with_env_or_str(log_level)? 72 Logger::try_with_env_or_str(log_level)?
76 .format(flexi_logger::colored_default_format) 73 .format(flexi_logger::colored_default_format)
77 //.set_palette("196;208;32;198;15".to_string()) 74 .set_palette("196;208;32;198;15".to_string())
78 .start()?; 75 .start()?;
79 } 76 }
80 77
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 @@
1use std::path::{Path, PathBuf}; 1use std::{
2 collections::VecDeque,
3 path::{Path, PathBuf},
4};
2 5
3use crate::prelude::*; 6use crate::prelude::*;
4 7
@@ -123,3 +126,26 @@ pub fn collect_link_ids_by_base_paths(
123 .map(|l| l.id()) 126 .map(|l| l.id())
124 .collect() 127 .collect()
125} 128}
129
130/// Returns a list of canonical paths to all the files in `dir`. This includes files in
131/// subdirectories.
132/// Fails if dir isnt a directory or if there is some other io error.
133pub fn collect_files_in_dir(dir: impl Into<PathBuf>) -> anyhow::Result<Vec<PathBuf>> {
134 let mut paths = Vec::new();
135 let mut dirs = VecDeque::new();
136 dirs.push_back(dir.into());
137
138 while let Some(dir) = dirs.pop_front() {
139 for entry in std::fs::read_dir(dir)? {
140 let entry = entry?;
141 let filetype = entry.file_type()?;
142 if filetype.is_dir() {
143 dirs.push_back(entry.path());
144 } else {
145 paths.push(entry.path());
146 }
147 }
148 }
149
150 Ok(paths)
151}