mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 12:24:56 +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::Command;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
|
|
||||||
pub fn postproc_line_prefix(
|
pub fn postproc_line_prefix(
|
||||||
line_prefix: &str,
|
line_prefix: &str,
|
||||||
inp: &mut dyn Read,
|
inp: &mut dyn Read,
|
||||||
@ -14,7 +13,18 @@ pub fn postproc_line_prefix(
|
|||||||
//std::io::copy(inp, oup)?;
|
//std::io::copy(inp, oup)?;
|
||||||
|
|
||||||
for line in BufReader::new(inp).lines() {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ fn main() -> Result<(), Error> {
|
|||||||
std::env::current_dir()?.join(&filepath)
|
std::env::current_dir()?.join(&filepath)
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!("abs path: {:?}", path);
|
|
||||||
|
|
||||||
let ai = AdaptInfo {
|
let ai = AdaptInfo {
|
||||||
inp: &mut File::open(&path)?,
|
inp: &mut File::open(&path)?,
|
||||||
filepath_hint: &path,
|
filepath_hint: &path,
|
||||||
|
@ -54,7 +54,7 @@ pub fn rga_preproc<'a>(
|
|||||||
.file_name()
|
.file_name()
|
||||||
.ok_or_else(|| format_err!("Empty filename"))?;
|
.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!(
|
/*let mimetype = tree_magic::from_filepath(path).ok_or(lerr(format!(
|
||||||
"File {} does not exist",
|
"File {} does not exist",
|
||||||
@ -103,7 +103,6 @@ pub fn rga_preproc<'a>(
|
|||||||
None => {
|
None => {
|
||||||
drop(reader);
|
drop(reader);
|
||||||
let mut compbuf = CachingWriter::new(oup, MAX_DB_BLOB_LEN, ZSTD_LEVEL)?;
|
let mut compbuf = CachingWriter::new(oup, MAX_DB_BLOB_LEN, ZSTD_LEVEL)?;
|
||||||
// start dupe
|
|
||||||
eprintln!("adapting...");
|
eprintln!("adapting...");
|
||||||
ad.adapt(AdaptInfo {
|
ad.adapt(AdaptInfo {
|
||||||
line_prefix,
|
line_prefix,
|
||||||
@ -112,7 +111,6 @@ pub fn rga_preproc<'a>(
|
|||||||
inp,
|
inp,
|
||||||
oup: &mut compbuf,
|
oup: &mut compbuf,
|
||||||
})?;
|
})?;
|
||||||
// end dupe
|
|
||||||
let compressed = compbuf.finish()?;
|
let compressed = compbuf.finish()?;
|
||||||
if let Some(cached) = compressed {
|
if let Some(cached) = compressed {
|
||||||
eprintln!("compressed len: {}", cached.len());
|
eprintln!("compressed len: {}", cached.len());
|
||||||
@ -132,8 +130,6 @@ pub fn rga_preproc<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// todo: duplicate code
|
|
||||||
// start dupe
|
|
||||||
eprintln!("adapting...");
|
eprintln!("adapting...");
|
||||||
ad.adapt(AdaptInfo {
|
ad.adapt(AdaptInfo {
|
||||||
line_prefix,
|
line_prefix,
|
||||||
@ -142,7 +138,6 @@ pub fn rga_preproc<'a>(
|
|||||||
inp,
|
inp,
|
||||||
oup,
|
oup,
|
||||||
})?;
|
})?;
|
||||||
// end dupe
|
|
||||||
Ok(())
|
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
|
// allow passthrough if the file is in an archive, otherwise it should have been filtered out by rg
|
||||||
let allow_cat = !is_real_file;
|
let allow_cat = !is_real_file;
|
||||||
if allow_cat {
|
if allow_cat {
|
||||||
let stdini = std::io::stdin();
|
spawning::postproc_line_prefix(line_prefix, inp, oup)?;
|
||||||
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)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(format_err!("No adapter found for file {:?}", filename))
|
Err(format_err!("No adapter found for file {:?}", filename))
|
||||||
|
Loading…
Reference in New Issue
Block a user