mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 04:14:57 +00:00
fix --rga-accurate (matching by mime types)
This commit is contained in:
parent
e9bd500c1e
commit
bca435557b
BIN
exampledir/sqlitedb
Normal file
BIN
exampledir/sqlitedb
Normal file
Binary file not shown.
@ -125,6 +125,7 @@ impl FileAdapter for FFmpegAdapter {
|
||||
let stdo = cmd.stdout.as_mut().expect("is piped");
|
||||
let time_re = Regex::new(r".*\d.*-->.*\d.*").unwrap();
|
||||
let mut time: String = "".to_owned();
|
||||
// rewrite subtitle times so they are prefixed in every line
|
||||
for line in BufReader::new(stdo).lines() {
|
||||
let line = line?;
|
||||
// 09:55.195 --> 09:56.730
|
||||
|
@ -4,7 +4,7 @@ use rga::adapters::*;
|
||||
use rga::preproc::*;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
fn main() -> Fallible<()> {
|
||||
env_logger::init();
|
||||
let empty: Vec<std::ffi::OsString> = vec![];
|
||||
@ -19,7 +19,7 @@ fn main() -> Fallible<()> {
|
||||
std::env::current_dir()?.join(&filepath)
|
||||
};
|
||||
|
||||
let i = File::open(&path)?;
|
||||
let mut i = File::open(&path)?;
|
||||
let mut o = std::io::stdout();
|
||||
let cache = if args.no_cache {
|
||||
None
|
||||
@ -27,7 +27,7 @@ fn main() -> Fallible<()> {
|
||||
Some(rga::preproc_cache::open()?)
|
||||
};
|
||||
let ai = AdaptInfo {
|
||||
inp: &mut BufReader::new(i),
|
||||
inp: &mut i,
|
||||
filepath_hint: &path,
|
||||
is_real_file: true,
|
||||
oup: &mut o,
|
||||
|
@ -4,10 +4,8 @@ use rga::adapters::spawning::map_exe_error;
|
||||
use rga::adapters::*;
|
||||
use rga::args::*;
|
||||
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
|
||||
fn main() -> Fallible<()> {
|
||||
env_logger::init();
|
||||
|
||||
@ -35,6 +33,7 @@ fn main() -> Fallible<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let pre_glob = if !args.accurate {
|
||||
let extensions = adapters
|
||||
.iter()
|
||||
.flat_map(|a| &a.metadata().fast_matchers)
|
||||
@ -43,6 +42,10 @@ fn main() -> Fallible<()> {
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
format!("*.{{{}}}", extensions)
|
||||
} else {
|
||||
"*".to_owned()
|
||||
};
|
||||
|
||||
let exe = std::env::current_exe().expect("Could not get executable location");
|
||||
let preproc_exe = exe.with_file_name("rga-preproc");
|
||||
@ -51,7 +54,7 @@ fn main() -> Fallible<()> {
|
||||
.arg("--pre")
|
||||
.arg(preproc_exe)
|
||||
.arg("--pre-glob")
|
||||
.arg(format!("*.{{{}}}", extensions))
|
||||
.arg(pre_glob)
|
||||
.args(passthrough_args)
|
||||
.spawn()
|
||||
.map_err(|e| map_exe_error(e, "rg", "Please make sure you have ripgrep installed."))?;
|
||||
|
@ -5,6 +5,8 @@ use failure::Fallible;
|
||||
use failure::{format_err, Error};
|
||||
use path_clean::PathClean;
|
||||
use std::convert::TryInto;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::io::BufWriter;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
@ -43,13 +45,20 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> {
|
||||
|
||||
eprintln!("path_hint: {:?}", filepath_hint);
|
||||
|
||||
/*let mimetype = tree_magic::from_filepath(path).ok_or(lerr(format!(
|
||||
"File {} does not exist",
|
||||
filename.to_string_lossy()
|
||||
)))?;
|
||||
println!("mimetype: {:?}", mimetype);*/
|
||||
// todo: figure out when using a bufreader is a good idea and when it is not
|
||||
// seems to beed for File::open() reads, but not sure about within archives (tar, zip)
|
||||
let inp = &mut BufReader::with_capacity(1 << 13, inp);
|
||||
|
||||
let mimetype = if args.accurate {
|
||||
let buf = inp.fill_buf()?; // fill but do not consume!
|
||||
let mimetype = tree_magic::from_u8(buf);
|
||||
eprintln!("mimetype: {:?}", mimetype);
|
||||
Some(mimetype)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let adapter = adapters(FileMeta {
|
||||
mimetype: None,
|
||||
mimetype,
|
||||
lossy_filename: filename.to_string_lossy().to_string(),
|
||||
});
|
||||
match adapter {
|
||||
|
Loading…
Reference in New Issue
Block a user