From 0e6e9417f1b16bde7ad4db009611f3923f1412e5 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 24 Nov 2023 14:56:00 -0500 Subject: log: add message when a binary file is skipped The way we do this is a little hokey but I believe it is correct. Fixes #2246 --- crates/printer/src/json.rs | 17 +++++++++++++++++ crates/printer/src/standard.rs | 11 ++++++++++- crates/printer/src/summary.rs | 17 +++++++++++++++++ crates/printer/src/util.rs | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/printer/src/json.rs b/crates/printer/src/json.rs index de4da9cc..82ad94de 100644 --- a/crates/printer/src/json.rs +++ b/crates/printer/src/json.rs @@ -755,6 +755,23 @@ impl<'p, 's, M: Matcher, W: io::Write> Sink for JSONSink<'p, 's, M, W> { Ok(!self.should_quit()) } + fn binary_data( + &mut self, + searcher: &Searcher, + binary_byte_offset: u64, + ) -> Result { + if searcher.binary_detection().quit_byte().is_some() { + if let Some(ref path) = self.path { + log::debug!( + "ignoring {path}: found binary data at \ + offset {binary_byte_offset}", + path = path.display(), + ); + } + } + Ok(true) + } + fn begin(&mut self, _searcher: &Searcher) -> Result { self.json.wtr.reset_count(); self.start_time = Instant::now(); diff --git a/crates/printer/src/standard.rs b/crates/printer/src/standard.rs index 78489906..6cc5374f 100644 --- a/crates/printer/src/standard.rs +++ b/crates/printer/src/standard.rs @@ -884,9 +884,18 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for StandardSink<'p, 's, M, W> { fn binary_data( &mut self, - _searcher: &Searcher, + searcher: &Searcher, binary_byte_offset: u64, ) -> Result { + if searcher.binary_detection().quit_byte().is_some() { + if let Some(ref path) = self.path { + log::debug!( + "ignoring {path}: found binary data at \ + offset {binary_byte_offset}", + path = path.as_path().display(), + ); + } + } self.binary_byte_offset = Some(binary_byte_offset); Ok(true) } diff --git a/crates/printer/src/summary.rs b/crates/printer/src/summary.rs index e69703fe..275419d4 100644 --- a/crates/printer/src/summary.rs +++ b/crates/printer/src/summary.rs @@ -688,6 +688,23 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> { Ok(!self.should_quit()) } + fn binary_data( + &mut self, + searcher: &Searcher, + binary_byte_offset: u64, + ) -> Result { + if searcher.binary_detection().quit_byte().is_some() { + if let Some(ref path) = self.path { + log::debug!( + "ignoring {path}: found binary data at \ + offset {binary_byte_offset}", + path = path.as_path().display(), + ); + } + } + Ok(true) + } + fn begin(&mut self, _searcher: &Searcher) -> Result { if self.path.is_none() && self.summary.config.kind.requires_path() { return Err(io::Error::error_message(format!( diff --git a/crates/printer/src/util.rs b/crates/printer/src/util.rs index 04f9e129..825f81c1 100644 --- a/crates/printer/src/util.rs +++ b/crates/printer/src/util.rs @@ -344,7 +344,7 @@ impl<'a> PrinterPath<'a> { } /// Return this path as an actual `Path` type. - fn as_path(&self) -> &Path { + pub(crate) fn as_path(&self) -> &Path { #[cfg(unix)] fn imp<'p>(p: &'p PrinterPath<'_>) -> &'p Path { use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; -- cgit v1.2.3