Skip to content

Commit

Permalink
fix(cli): print paths relative to the target path.
Browse files Browse the repository at this point in the history
When the target path passed to the CLI is a relative one, file paths printed by the CLI are relative to the target path.

Closes #212
  • Loading branch information
plusvic committed Oct 9, 2024
1 parent eda7ab4 commit 7fffb58
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cli/src/commands/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ pub fn exec_scan(args: &ArgMatches) -> anyhow::Result<()> {
walk::ParWalker::path(target_path)
};

let canonical_target_path = target_path.canonicalize()?;

if let Some(num_threads) = num_threads {
w.num_threads(*num_threads);
}
Expand Down Expand Up @@ -305,11 +307,20 @@ pub fn exec_scan(args: &ArgMatches) -> anyhow::Result<()> {

let now = Instant::now();

// When the target path passed in the command line is an absolute
// path, all file paths are printed as absolute paths, if not, they
// are printed as paths relative to the target path.
let printable_path = if target_path.is_absolute() {
file_path.as_path()
} else {
file_path.strip_prefix(&canonical_target_path)?
};

state
.files_in_progress
.lock()
.unwrap()
.push((file_path.clone(), now));
.push((printable_path.to_path_buf(), now));

let scan_options = all_metadata.iter().fold(
ScanOptions::new(),
Expand All @@ -326,11 +337,15 @@ pub fn exec_scan(args: &ArgMatches) -> anyhow::Result<()> {
.files_in_progress
.lock()
.unwrap()
.retain(|(p, _)| !file_path.eq(p));
.retain(|(p, _)| !printable_path.eq(p));

let scan_results = scan_results?;
let matched_count =
process_scan_results(args, &file_path, &scan_results, output);
let matched_count = process_scan_results(
args,
printable_path,
&scan_results,
output,
);

state.num_scanned_files.fetch_add(1, Ordering::Relaxed);
if matched_count > 0 {
Expand Down

0 comments on commit 7fffb58

Please sign in to comment.