mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-09 14:30:37 +00:00
fix passthrough, invalid encodings
This commit is contained in:
parent
0c3bcfd115
commit
2d20563e2c
@ -5,7 +5,6 @@ use std::io::BufReader;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
|
||||
|
||||
pub fn postproc_line_prefix(
|
||||
line_prefix: &str,
|
||||
inp: &mut dyn Read,
|
||||
@ -14,7 +13,18 @@ pub fn postproc_line_prefix(
|
||||
//std::io::copy(inp, oup)?;
|
||||
|
||||
for line in BufReader::new(inp).lines() {
|
||||
oup.write_all(format!("{}{}\n", line_prefix, line?).as_bytes())?;
|
||||
match line {
|
||||
Ok(line) => {
|
||||
oup.write_all(format!("{}{}\n", line_prefix, line).as_bytes())?;
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::InvalidData {
|
||||
oup.write_all(format!("{}[binary]\n", line_prefix).as_bytes())?;
|
||||
} else {
|
||||
Err(e)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ fn main() -> Result<(), Error> {
|
||||
std::env::current_dir()?.join(&filepath)
|
||||
};
|
||||
|
||||
eprintln!("abs path: {:?}", path);
|
||||
|
||||
let ai = AdaptInfo {
|
||||
inp: &mut File::open(&path)?,
|
||||
filepath_hint: &path,
|
||||
|
@ -54,7 +54,7 @@ pub fn rga_preproc<'a>(
|
||||
.file_name()
|
||||
.ok_or_else(|| format_err!("Empty filename"))?;
|
||||
|
||||
eprintln!("abs path: {:?}", filepath_hint);
|
||||
eprintln!("path_hint: {:?}", filepath_hint);
|
||||
|
||||
/*let mimetype = tree_magic::from_filepath(path).ok_or(lerr(format!(
|
||||
"File {} does not exist",
|
||||
@ -103,7 +103,6 @@ pub fn rga_preproc<'a>(
|
||||
None => {
|
||||
drop(reader);
|
||||
let mut compbuf = CachingWriter::new(oup, MAX_DB_BLOB_LEN, ZSTD_LEVEL)?;
|
||||
// start dupe
|
||||
eprintln!("adapting...");
|
||||
ad.adapt(AdaptInfo {
|
||||
line_prefix,
|
||||
@ -112,7 +111,6 @@ pub fn rga_preproc<'a>(
|
||||
inp,
|
||||
oup: &mut compbuf,
|
||||
})?;
|
||||
// end dupe
|
||||
let compressed = compbuf.finish()?;
|
||||
if let Some(cached) = compressed {
|
||||
eprintln!("compressed len: {}", cached.len());
|
||||
@ -132,8 +130,6 @@ pub fn rga_preproc<'a>(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// todo: duplicate code
|
||||
// start dupe
|
||||
eprintln!("adapting...");
|
||||
ad.adapt(AdaptInfo {
|
||||
line_prefix,
|
||||
@ -142,7 +138,6 @@ pub fn rga_preproc<'a>(
|
||||
inp,
|
||||
oup,
|
||||
})?;
|
||||
// end dupe
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -150,11 +145,7 @@ pub fn rga_preproc<'a>(
|
||||
// allow passthrough if the file is in an archive, otherwise it should have been filtered out by rg
|
||||
let allow_cat = !is_real_file;
|
||||
if allow_cat {
|
||||
let stdini = std::io::stdin();
|
||||
let mut stdin = stdini.lock();
|
||||
let stdouti = std::io::stdout();
|
||||
let mut stdout = stdouti.lock();
|
||||
spawning::postproc_line_prefix(line_prefix, &mut stdin, &mut stdout)?;
|
||||
spawning::postproc_line_prefix(line_prefix, inp, oup)?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format_err!("No adapter found for file {:?}", filename))
|
||||
|
Loading…
Reference in New Issue
Block a user