diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc9cba..a4eea47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog -## 3.1.1 - +## 3.1.0 +- Properly resolve symlinks ## 3.0.1 diff --git a/src/config/mod.rs b/src/config/mod.rs index 2383d65..fd223bb 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -119,17 +119,30 @@ fn get_output(has_data_from_stdin: bool, is_print_flag: bool, suppress_output: b } fn determine_input(path: String) -> Result { - match check_path_type(&path)? { + let canonical_path = fs::canonicalize(&path).map_err(|_| Error { + exit_code: GENERAL_ERROR, + message: format!("{}: No such file or directory", path.red()), + })?; + + let canonical_path_str = canonical_path.to_str().ok_or(Error { + exit_code: GENERAL_ERROR, + message: "Canonical path contains invalid UTF-8 characters".into(), + })?; + + match check_path_type(&canonical_path)? { PathType::File => { - let line_count = count_lines(&path); - Ok(Input::File(PathAndLineCount { path, line_count })) + let line_count = count_lines(&canonical_path); + Ok(Input::File(PathAndLineCount { + path: canonical_path_str.to_string(), + line_count, + })) } PathType::Folder => { - let mut paths = list_files_in_directory(Path::new(&path))?; + let mut paths = list_files_in_directory(&canonical_path)?; paths.sort(); Ok(Input::Folder(FolderInfo { - folder_name: path, + folder_name: canonical_path_str.to_string(), file_paths: paths, })) } diff --git a/src/main.rs b/src/main.rs index 625fbe0..eb4456a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ mod types; use crate::cli::Cli; use crate::highlight_processor::HighlightProcessor; +use crate::highlighters::Highlighters; use crate::io::controller::get_io_and_presenter; use crate::io::presenter::Present; use crate::io::reader::AsyncLineReader; @@ -39,7 +40,7 @@ pub async fn run(theme: Theme, config: Config, cli: Cli) { let (reached_eof_tx, reached_eof_rx) = oneshot::channel::<()>(); let (io, presenter) = get_io_and_presenter(config, Some(reached_eof_tx)).await; - let highlighter = highlighters::Highlighters::new(&theme, &cli); + let highlighter = Highlighters::new(&theme, &cli); let highlight_processor = HighlightProcessor::new(highlighter); tokio::spawn(process_lines(io, highlight_processor));