this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(backends): unify single + shortcut extension lookup in chain_from_ext

+27 -24
+17
src/backends/mod.rs
··· 42 42 _ => None, 43 43 } 44 44 } 45 + 46 + /// Resolve an extension to a compressor chain in innermost→outermost order. 47 + /// Single-codec extensions (`gz`, `xz`, `tar`, …) produce a one-element chain; 48 + /// compound shortcut extensions (`tgz`, `tbz`, `tbz2`, `txz`, `tzst`) expand 49 + /// into the chain they represent (e.g. `tgz` → `[tar, gz]`). 50 + /// 51 + /// This is the single source of truth for what any archive-like extension 52 + /// means. Both single extensions and compound shortcuts flow through here. 53 + pub fn chain_from_ext(ext: &str) -> Option<Vec<Box<dyn Compressor>>> { 54 + match ext { 55 + "tgz" => Some(vec![Box::<Tar>::default(), Box::<Gzip>::default()]), 56 + "tbz" | "tbz2" => Some(vec![Box::<Tar>::default(), Box::<Bzip2>::default()]), 57 + "txz" => Some(vec![Box::<Tar>::default(), Box::<Xz>::default()]), 58 + "tzst" => Some(vec![Box::<Tar>::default(), Box::<Zstd>::default()]), 59 + _ => compressor_from_str(ext).map(|c| vec![c]), 60 + } 61 + }
+10 -24
src/job.rs
··· 361 361 } 362 362 } 363 363 364 - /// Expand a compound shortcut extension like `.tgz` into its equivalent 365 - /// compressor chain, in innermost-to-outermost order. Returns `None` for 366 - /// extensions that aren't a known shortcut. 367 - fn expand_shortcut_ext(ext: &str) -> Option<&'static [&'static str]> { 368 - match ext { 369 - "tgz" => Some(&["tar", "gz"]), 370 - "tbz" | "tbz2" => Some(&["tar", "bz2"]), 371 - "txz" => Some(&["tar", "xz"]), 372 - "tzst" => Some(&["tar", "zst"]), 373 - _ => None, 374 - } 375 - } 376 - 377 364 /// Get a compressor pipeline from a filename by scanning extensions right-to-left 378 365 pub fn get_compressor_from_filename(filename: &Path) -> Option<Box<dyn Compressor>> { 379 366 let file_name = filename.file_name()?.to_str()?; ··· 386 373 // Scan extensions right-to-left, collecting known compressors 387 374 // until hitting an unknown extension or the base name. 388 375 // e.g., "a.b.tar.gz" → gz ✓, tar ✓, b ✗ stop → [gz, tar] 389 - // Compound shortcuts like "tgz" expand to their component chain, so 390 - // "archive.tgz" behaves identically to "archive.tar.gz". 376 + // `chain_from_ext` handles both single-codec extensions and compound 377 + // shortcuts like `tgz` (which expand to `[tar, gz]`). 391 378 let mut compressor_names: Vec<String> = Vec::new(); 392 379 for ext in parts[1..].iter().rev() { 393 - if let Some(chain) = expand_shortcut_ext(ext) { 394 - // chain is innermost→outermost; we push in right-to-left order 395 - // (outermost first) to match how we're walking the filename. 396 - for name in chain.iter().rev() { 397 - compressor_names.push((*name).to_string()); 380 + match backends::chain_from_ext(ext) { 381 + Some(chain) => { 382 + // chain is innermost→outermost; we walk the filename 383 + // right-to-left so we push outermost first. 384 + for c in chain.iter().rev() { 385 + compressor_names.push(c.name().to_string()); 386 + } 398 387 } 399 - } else if let Some(c) = backends::compressor_from_str(ext) { 400 - compressor_names.push(c.name().to_string()); 401 - } else { 402 - break; 388 + None => break, 403 389 } 404 390 } 405 391