mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 12:24:56 +00:00
not working
This commit is contained in:
parent
7984d5f784
commit
2b4caf067b
BIN
exampledir/test/only-seek-zip.zip
Normal file
BIN
exampledir/test/only-seek-zip.zip
Normal file
Binary file not shown.
@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||
pub mod sqlite;
|
||||
pub mod tar;
|
||||
// pub mod writing;
|
||||
// pub mod zip;
|
||||
pub mod zip;
|
||||
use crate::{adapted_iter::AdaptedFilesIterBox, config::RgaConfig, matching::*};
|
||||
use anyhow::{format_err, Context, Result};
|
||||
use custom::CustomAdapterConfig;
|
||||
@ -113,7 +113,7 @@ pub fn get_all_adapters(custom_adapters: Option<Vec<CustomAdapterConfig>>) -> Ad
|
||||
let internal_adapters: Vec<Arc<dyn FileAdapter>> = vec![
|
||||
Arc::new(PostprocPageBreaks::default()),
|
||||
//Rc::new(ffmpeg::FFmpegAdapter::new()),
|
||||
// Rc::new(zip::ZipAdapter::new()),
|
||||
Arc::new(zip::ZipAdapter::new()),
|
||||
Arc::new(decompress::DecompressAdapter::new()),
|
||||
Arc::new(tar::TarAdapter::new()),
|
||||
//Rc::new(sqlite::SqliteAdapter::new()),
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::{any::Any, io::Cursor};
|
||||
|
||||
use super::*;
|
||||
use crate::{adapted_iter::AdaptedFilesIter, print_bytes};
|
||||
use anyhow::*;
|
||||
@ -5,6 +7,11 @@ use async_stream::stream;
|
||||
use async_zip::read::stream::ZipFileReader;
|
||||
use lazy_static::lazy_static;
|
||||
use log::*;
|
||||
use tokio::{
|
||||
io::AsyncReadExt,
|
||||
sync::mpsc::{self, Sender},
|
||||
};
|
||||
use tokio_stream::wrappers::ReceiverStream;
|
||||
|
||||
static EXTENSIONS: &[&str] = &["zip"];
|
||||
|
||||
@ -37,8 +44,7 @@ impl GetMetadata for ZipAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
impl FileAdapter for ZipAdapter {
|
||||
fn adapt(&self, ai: AdaptInfo, _detection_reason: &FileMatcher) -> Result<AdaptedFilesIterBox> {
|
||||
async fn yielder(ai: AdaptInfo, s: Sender<Result<AdaptInfo>>) -> Result<()> {
|
||||
let AdaptInfo {
|
||||
inp,
|
||||
filepath_hint,
|
||||
@ -50,13 +56,12 @@ impl FileAdapter for ZipAdapter {
|
||||
} = ai;
|
||||
let mut zip = ZipFileReader::new(inp);
|
||||
|
||||
let s = stream! {
|
||||
while !zip.finished() {
|
||||
if let Some(mut reader) = zip.entry_reader().await? {
|
||||
let file = reader.entry();
|
||||
/* if file.is_dir() {
|
||||
if file.filename().ends_with("/") {
|
||||
continue;
|
||||
}*/
|
||||
}
|
||||
debug!(
|
||||
"{}{}|{}: {} ({} packed)",
|
||||
line_prefix,
|
||||
@ -66,19 +71,38 @@ impl FileAdapter for ZipAdapter {
|
||||
print_bytes(file.compressed_size() as f64)
|
||||
);
|
||||
let new_line_prefix = format!("{}{}: ", line_prefix, file.filename());
|
||||
yield Ok(AdaptInfo {
|
||||
filepath_hint: PathBuf::from(file.filename()),
|
||||
let fname = PathBuf::from(file.filename());
|
||||
drop(file);
|
||||
tokio::pin!(reader);
|
||||
// SAFETY: this should be solvable without unsafe but idk how :(
|
||||
let reader2 = unsafe {
|
||||
std::intrinsics::transmute::<
|
||||
Pin<&mut (dyn AsyncRead + Send)>,
|
||||
Pin<&'static mut (dyn AsyncRead + Send)>,
|
||||
>(reader)
|
||||
};
|
||||
s.send(Ok(AdaptInfo {
|
||||
filepath_hint: fname,
|
||||
is_real_file: false,
|
||||
inp: Box::pin(reader),
|
||||
inp: Box::pin(reader2),
|
||||
line_prefix: new_line_prefix,
|
||||
archive_recursion_depth: archive_recursion_depth + 1,
|
||||
postprocess,
|
||||
config: config.clone(),
|
||||
});
|
||||
}))
|
||||
.await
|
||||
.map_err(|_| anyhow!("could not send adaptinfo"))?;
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(Box::pin(s))
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl FileAdapter for ZipAdapter {
|
||||
fn adapt(&self, ai: AdaptInfo, _detection_reason: &FileMatcher) -> Result<AdaptedFilesIterBox> {
|
||||
let (s, r) = mpsc::channel(1);
|
||||
tokio::spawn(yielder(ai, s));
|
||||
Ok(Box::pin(ReceiverStream::new(r)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,6 +167,12 @@ mod test {
|
||||
// Dropping the `ZipWriter` will have the same effect, but may silently fail
|
||||
Ok(zip.finish()?.into_inner())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_seek_zip() -> Result<()> {
|
||||
let zip = test_data_dir().join("only-seek-zip.zip");
|
||||
Ok(())
|
||||
}
|
||||
#[test]
|
||||
fn recurse() -> Result<()> {
|
||||
let zipfile = create_zip("outer.txt", "outer text file", true)?;
|
||||
|
Loading…
Reference in New Issue
Block a user