diff --git a/src/scanner/util.rs b/src/scanner/util.rs index ac33c9c..f36bb41 100644 --- a/src/scanner/util.rs +++ b/src/scanner/util.rs @@ -10,7 +10,9 @@ pub fn is_compressed_file(path: &Path) -> bool { }; // Check for compound extensions first if filename.ends_with(".tar.gz") + || filename.ends_with(".tar.gzip") || filename.ends_with(".tar.bz2") + || filename.ends_with(".tar.bzip2") || filename.ends_with(".tar.xz") { return true; @@ -19,8 +21,10 @@ pub fn is_compressed_file(path: &Path) -> bool { if let Some(ext) = path.extension().and_then(|s| s.to_str()) { let ext_lower = ext.to_lowercase(); ext_lower == "gz" + || ext_lower == "gzip" || ext_lower == "tgz" || ext_lower == "bz2" + || ext_lower == "bzip2" || ext_lower == "xz" || ext_lower == "tar" || ext_lower == "zlib" @@ -63,3 +67,22 @@ pub fn is_sqlite_file(path: &Path) -> bool { pub fn has_sqlite_magic(data: &[u8]) -> bool { data.len() >= SQLITE_MAGIC.len() && data[..SQLITE_MAGIC.len()] == *SQLITE_MAGIC } + +#[cfg(test)] +mod tests { + use std::path::Path; + + use super::is_compressed_file; + + #[test] + fn recognizes_tar_wrapped_long_compression_extensions() { + assert!(is_compressed_file(Path::new("archive.tar.gzip"))); + assert!(is_compressed_file(Path::new("archive.tar.bzip2"))); + } + + #[test] + fn recognizes_long_single_compression_extensions() { + assert!(is_compressed_file(Path::new("payload.gzip"))); + assert!(is_compressed_file(Path::new("payload.bzip2"))); + } +}