diff --git a/exampledir/compress/test.log b/exampledir/decompress/test.log similarity index 100% rename from exampledir/compress/test.log rename to exampledir/decompress/test.log diff --git a/exampledir/compress/test.log.bz2 b/exampledir/decompress/test.log.bz2 similarity index 100% rename from exampledir/compress/test.log.bz2 rename to exampledir/decompress/test.log.bz2 diff --git a/exampledir/compress/test.log.gz b/exampledir/decompress/test.log.gz similarity index 100% rename from exampledir/compress/test.log.gz rename to exampledir/decompress/test.log.gz diff --git a/exampledir/compress/test.log.xz b/exampledir/decompress/test.log.xz similarity index 100% rename from exampledir/compress/test.log.xz rename to exampledir/decompress/test.log.xz diff --git a/exampledir/compress/test.log.zst b/exampledir/decompress/test.log.zst similarity index 100% rename from exampledir/compress/test.log.zst rename to exampledir/decompress/test.log.zst diff --git a/exampledir/decompress/testlogbutwithoutextension b/exampledir/decompress/testlogbutwithoutextension new file mode 100644 index 0000000..ed0a24c Binary files /dev/null and b/exampledir/decompress/testlogbutwithoutextension differ diff --git a/exampledir/exampledir.tar.gz b/exampledir/tar/exampledir.tar.gz similarity index 100% rename from exampledir/exampledir.tar.gz rename to exampledir/tar/exampledir.tar.gz diff --git a/exampledir/test.tar b/exampledir/tar/test.tar similarity index 100% rename from exampledir/test.tar rename to exampledir/tar/test.tar diff --git a/exampledir/test.tar.bz2 b/exampledir/tar/test.tar.bz2 similarity index 100% rename from exampledir/test.tar.bz2 rename to exampledir/tar/test.tar.bz2 diff --git a/exampledir/tar/test.tar.zip b/exampledir/tar/test.tar.zip new file mode 100644 index 0000000..d55c53e Binary files /dev/null and b/exampledir/tar/test.tar.zip differ diff --git a/src/adapters/decompress.rs b/src/adapters/decompress.rs index 141f0da..d92c500 100644 --- a/src/adapters/decompress.rs +++ b/src/adapters/decompress.rs @@ -45,22 +45,33 @@ impl GetMetadata for DecompressAdapter { } } -fn decompress_any<'a, R>(filename: &Path, inp: &'a mut R) -> Fallible> +fn decompress_any<'a, R>(reason: &SlowMatcher, inp: &'a mut R) -> Fallible> where R: Read, { - let extension = filename.extension().map(|e| e.to_string_lossy().to_owned()); + use FastMatcher::*; + use SlowMatcher::*; + let gz = |inp: &'a mut R| Box::new(flate2::read::MultiGzDecoder::new(inp)); + let bz2 = |inp: &'a mut R| Box::new(bzip2::read::BzDecoder::new(inp)); + let xz = |inp: &'a mut R| Box::new(xz2::read::XzDecoder::new_multi_decoder(inp)); + let zst = |inp: &'a mut R| zstd::stream::read::Decoder::new(inp); // returns result - match extension { - Some(e) => Ok(match e.to_owned().as_ref() { - "tgz" | "gz" => Box::new(flate2::read::MultiGzDecoder::new(inp)), - "tbz" | "tbz2" | "bz2" => Box::new(bzip2::read::BzDecoder::new(inp)), - "xz" => Box::new(xz2::read::XzDecoder::new_multi_decoder(inp)), - "zst" => Box::new(zstd::stream::read::Decoder::new(inp)?), + Ok(match reason { + Fast(FileExtension(ext)) => match ext.as_ref() { + "tgz" | "gz" => gz(inp), + "tbz" | "tbz2" | "bz2" => bz2(inp), + "xz" => xz(inp), + "zst" => Box::new(zst(inp)?), ext => Err(format_err!("don't know how to decompress {}", ext))?, - }), - None => Err(format_err!("no extension")), - } + }, + MimeType(mime) => match mime.as_ref() { + "application/gzip" => gz(inp), + "application/x-bzip" => bz2(inp), + "application/x-xz" => xz(inp), + "application/zstd" => Box::new(zst(inp)?), + mime => Err(format_err!("don't know how to decompress mime {}", mime))?, + }, + }) } fn get_inner_filename(filename: &Path) -> PathBuf { let extension = filename @@ -90,7 +101,7 @@ impl FileAdapter for DecompressAdapter { .. } = ai; - let mut decompress = decompress_any(filepath_hint, &mut inp)?; + let mut decompress = decompress_any(detection_reason, &mut inp)?; let ai2: AdaptInfo = AdaptInfo { filepath_hint: &get_inner_filename(filepath_hint), is_real_file: false, diff --git a/src/matching.rs b/src/matching.rs index 22b84c7..a62de7e 100644 --- a/src/matching.rs +++ b/src/matching.rs @@ -59,10 +59,14 @@ pub fn adapter_matcher>( use SlowMatcher::*; for matcher in metadata.get_matchers(slow) { match matcher.as_ref() { - f @ MimeType(re) => mime_regexes.push((re.clone(), adapter.clone(), f)), - f @ Fast(FastMatcher::FileExtension(re)) => { - fname_regexes.push((extension_to_regex(re), adapter.clone(), f)) + MimeType(re) => { + mime_regexes.push((re.clone(), adapter.clone(), MimeType(re.clone()))) } + Fast(FastMatcher::FileExtension(re)) => fname_regexes.push(( + extension_to_regex(re), + adapter.clone(), + Fast(FastMatcher::FileExtension(re.clone())), + )), }; } } @@ -112,11 +116,11 @@ pub fn adapter_matcher>( if fname_matches.is_empty() { None } else { - let (_, adapter, matcher) = fname_regexes[fname_matches[0]]; + let (_, adapter, matcher) = &fname_regexes[fname_matches[0]]; Some((adapter.clone(), matcher.clone())) } } else { - let (_, adapter, matcher) = mime_regexes[mime_matches[0]]; + let (_, adapter, matcher) = &mime_regexes[mime_matches[0]]; Some((adapter.clone(), matcher.clone())) } }) diff --git a/src/preproc.rs b/src/preproc.rs index a29bd4c..70719f6 100644 --- a/src/preproc.rs +++ b/src/preproc.rs @@ -101,7 +101,7 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> { archive_recursion_depth, config: PreprocConfig { cache: None, args }, }, - detection_reason, + &detection_reason, )?; let compressed = compbuf .into_inner() @@ -134,7 +134,7 @@ pub fn rga_preproc(ai: AdaptInfo) -> Result<(), Error> { archive_recursion_depth, config: PreprocConfig { cache: None, args }, }, - detection_reason, + &detection_reason, )?; Ok(()) }