Skip to content

Commit

Permalink
Properly resolve symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
bensadeh committed Apr 6, 2024
1 parent cfc0e85 commit 62e48f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changelog
## 3.1.1


## 3.1.0

- Properly resolve symlinks

## 3.0.1

Expand Down
23 changes: 18 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Input, Error> {
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,
}))
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 62e48f7

Please sign in to comment.