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