diff --git a/src/backend/aqua.rs b/src/backend/aqua.rs index 1aa6447883..e5ced3863b 100644 --- a/src/backend/aqua.rs +++ b/src/backend/aqua.rs @@ -7,7 +7,7 @@ use crate::backend::static_helpers::get_filename_from_url; use crate::cli::args::BackendArg; use crate::cli::version::{ARCH, OS}; use crate::config::Settings; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::http::HTTP; use crate::install_context::InstallContext; use crate::lockfile::{PlatformInfo, ProvenanceType}; @@ -1302,7 +1302,7 @@ impl AquaBackend { v: &str, ) -> Result { let format = pkg.format(v, os(), arch())?; - let format = Self::effective_archive_format(pkg, format)?; + let format = Self::effective_extraction_format(pkg, format)?; if !format.is_archive() { return Err(eyre!( "SLSA provenance subject mismatch and content-level fallback is only supported for archives" @@ -2295,17 +2295,21 @@ impl AquaBackend { } } - fn effective_archive_format(pkg: &AquaPackage, format: &str) -> Result { - let archive_format = TarFormat::from_ext(format); - if archive_format == TarFormat::Raw && !matches!(format, "" | "raw" | "dmg" | "pkg") { + fn effective_extraction_format(pkg: &AquaPackage, format: &str) -> Result { + let extraction_format = ExtractionFormat::from_ext(format); + if extraction_format == ExtractionFormat::Raw + && !matches!(format, "" | "raw" | "dmg" | "pkg") + { bail!("unsupported aqua package format: {format}"); } - if pkg.r#type == AquaPackageType::GithubArchive && archive_format == TarFormat::Raw { + if pkg.r#type == AquaPackageType::GithubArchive + && extraction_format == ExtractionFormat::Raw + { // The aqua registry can omit format for GitHub-generated archive downloads. // Historically Raw reached untar/open_tar, which treated it as gzip-tar. - Ok(TarFormat::TarGz) + Ok(ExtractionFormat::TarGz) } else { - Ok(archive_format) + Ok(extraction_format) } } @@ -2354,10 +2358,15 @@ impl AquaBackend { pr: Some(ctx.pr.as_ref()), ..Default::default() }; - let archive_format = Self::effective_archive_format(pkg, format)?; + let extraction_format = Self::effective_extraction_format(pkg, format)?; let mut make_executable = false; if let AquaPackageType::GithubArchive = pkg.r#type { - file::extract_archive(&tarball_path, &install_path, archive_format, &extract_opts)?; + file::extract_archive( + &tarball_path, + &install_path, + extraction_format, + &extract_opts, + )?; make_executable = true; } else if let AquaPackageType::GithubContent = pkg.r#type { if let Some(parent) = first_bin_path.parent() { @@ -2375,11 +2384,16 @@ impl AquaBackend { file::un_dmg(&tarball_path, &install_path)?; } else if format == "pkg" { file::un_pkg(&tarball_path, &install_path)?; - } else if archive_format.is_compressed_file() { - file::decompress_file(&tarball_path, first_bin_path, archive_format)?; + } else if extraction_format.is_compressed_file() { + file::decompress_file(&tarball_path, first_bin_path, extraction_format)?; make_executable = true; } else { - file::extract_archive(&tarball_path, &install_path, archive_format, &extract_opts)?; + file::extract_archive( + &tarball_path, + &install_path, + extraction_format, + &extract_opts, + )?; make_executable = true; } diff --git a/src/backend/asset_matcher.rs b/src/backend/asset_matcher.rs index b0e3d9e11b..e1f21b9fc3 100644 --- a/src/backend/asset_matcher.rs +++ b/src/backend/asset_matcher.rs @@ -22,7 +22,7 @@ use std::sync::LazyLock; use super::platform_target::PlatformTarget; use super::platform_tokens::is_platform_or_version_token; use super::static_helpers::get_filename_from_url; -use crate::file::TarFormat; +use crate::file::ExtractionFormat; use crate::http::HTTP; // ========== Platform Detection Types (from asset_detector) ========== @@ -522,9 +522,9 @@ impl AssetPicker { } fn score_format_preferences(&self, asset: &str) -> i32 { - let format = TarFormat::from_file_name(asset); + let format = ExtractionFormat::from_file_name(asset); - if format == TarFormat::Zip { + if format == ExtractionFormat::Zip { if self.target_os == "windows" { return 15; } else { diff --git a/src/backend/github.rs b/src/backend/github.rs index 291d1ecf7f..aea17dfd42 100644 --- a/src/backend/github.rs +++ b/src/backend/github.rs @@ -1989,9 +1989,9 @@ impl UnifiedGitBackend { ) -> Result { let raw_opts = tv.request.options(); let format = if let Some(format_opt) = lookup_with_fallback(&raw_opts, "format") { - file::TarFormat::from_ext(&format_opt) + file::ExtractionFormat::from_ext(&format_opt) } else { - file::TarFormat::from_file_name( + file::ExtractionFormat::from_file_name( &file_path.file_name().unwrap_or_default().to_string_lossy(), ) }; diff --git a/src/backend/http.rs b/src/backend/http.rs index 61f46444cb..3d679e84ba 100644 --- a/src/backend/http.rs +++ b/src/backend/http.rs @@ -57,7 +57,7 @@ struct FileInfo { /// File extension extension: String, /// Detected archive format - format: file::TarFormat, + format: file::ExtractionFormat, /// Whether this is a compressed single binary (not a tar archive) is_compressed_binary: bool, } @@ -81,7 +81,7 @@ impl FileInfo { }; let file_name = effective_path.file_name().unwrap().to_string_lossy(); - let format = file::TarFormat::from_file_name(&file_name); + let format = file::ExtractionFormat::from_file_name(&file_name); let extension = format .extension() @@ -94,7 +94,7 @@ impl FileInfo { .to_string() }); - let is_compressed_binary = !format.is_archive() && format != file::TarFormat::Raw; + let is_compressed_binary = !format.is_archive() && format != file::ExtractionFormat::Raw; Self { effective_path, @@ -286,7 +286,7 @@ impl HttpBackend { /// used different options (e.g., different `bin` name) fn extraction_type_from_cache(&self, cache_key: &str, file_info: &FileInfo) -> ExtractionType { // For archives, we don't need to detect the filename - if !file_info.is_compressed_binary && file_info.format != file::TarFormat::Raw { + if !file_info.is_compressed_binary && file_info.format != file::ExtractionFormat::Raw { return ExtractionType::Archive; } @@ -369,7 +369,7 @@ impl HttpBackend { if file_info.is_compressed_binary { self.extract_compressed_binary(dest, file_path, &file_info, opts, pr) - } else if file_info.format == file::TarFormat::Raw { + } else if file_info.format == file::ExtractionFormat::Raw { self.extract_raw_file(dest, file_path, &file_info, opts, pr) } else { self.extract_archive(tv, dest, file_path, &file_info, opts, pr) @@ -436,7 +436,7 @@ impl HttpBackend { opts.strip_components().and_then(|s| s.parse().ok()); // Auto-detect strip_components=1 for single-directory archives - let can_probe_strip = file_info.format != file::TarFormat::SevenZip || cfg!(windows); + let can_probe_strip = file_info.format != file::ExtractionFormat::SevenZip || cfg!(windows); if strip_components.is_none() && opts.bin_path().is_none() && can_probe_strip diff --git a/src/backend/static_helpers.rs b/src/backend/static_helpers.rs index 3e3cd5aae8..410e0e3daf 100644 --- a/src/backend/static_helpers.rs +++ b/src/backend/static_helpers.rs @@ -399,12 +399,12 @@ pub fn install_artifact( file::remove_all(&install_path)?; file::create_dir_all(&install_path)?; - // Use TarFormat for format detection + // Use ExtractionFormat for format detection // Check for explicit format option first, then fall back to file extension let format = if let Some(format_opt) = lookup_with_fallback(opts, "format") { - file::TarFormat::from_ext(&format_opt) + file::ExtractionFormat::from_ext(&format_opt) } else { - file::TarFormat::from_file_name( + file::ExtractionFormat::from_file_name( &file_path.file_name().unwrap_or_default().to_string_lossy(), ) }; @@ -412,7 +412,7 @@ pub fn install_artifact( // Get file extension and detect format let file_name = file_path.file_name().unwrap().to_string_lossy(); - if !format.is_archive() && format != file::TarFormat::Raw { + if !format.is_archive() && format != file::ExtractionFormat::Raw { // Handle compressed single binary let ext = Path::new(&*file_name) .extension() @@ -438,7 +438,7 @@ pub fn install_artifact( file::decompress_file(file_path, &dest, format)?; file::make_executable(&dest)?; - } else if format == file::TarFormat::Raw { + } else if format == file::ExtractionFormat::Raw { // Copy the file directly to the bin_path directory or install_path if let Some(bin_path_template) = lookup_with_fallback(opts, "bin_path") { let bin_path = template_string(&bin_path_template, tv); diff --git a/src/cli/generate/tool_stub.rs b/src/cli/generate/tool_stub.rs index 61db2d7d1c..f133fc40b1 100644 --- a/src/cli/generate/tool_stub.rs +++ b/src/cli/generate/tool_stub.rs @@ -4,7 +4,7 @@ use crate::backend::platform_target::PlatformTarget; use crate::backend::static_helpers::get_filename_from_url; use crate::cli::tool_stub::ToolStubFile; use crate::config::Config; -use crate::file::{self, TarFormat}; +use crate::file::{self, ExtractionFormat}; use crate::http::HTTP; use crate::lockfile::PlatformInfo; use crate::minisign; @@ -471,7 +471,7 @@ exec "$MISE_BIN" tool-stub "$0" "$@" let checksum = format!("blake3:{}", blake3::hash(&bytes).to_hex()); // Detect binary path if this is an archive - let bin_path = if TarFormat::from_file_name(&filename).is_archive() { + let bin_path = if ExtractionFormat::from_file_name(&filename).is_archive() { // Update progress message for extraction and reuse the same progress reporter pr.set_message(format!("extract {filename}")); match self @@ -508,7 +508,7 @@ exec "$MISE_BIN" tool-stub "$0" "$@" std::fs::create_dir_all(&extracted_dir)?; // Try extraction using mise's built-in extraction logic (reuse the passed progress reporter) - let format = TarFormat::from_file_name( + let format = ExtractionFormat::from_file_name( &archive_path .file_name() .unwrap_or_default() @@ -526,7 +526,7 @@ exec "$MISE_BIN" tool-stub "$0" "$@" // Check if strip_components would be applied during actual installation let format = - TarFormat::from_file_name(&archive_path.file_name().unwrap().to_string_lossy()); + ExtractionFormat::from_file_name(&archive_path.file_name().unwrap().to_string_lossy()); let will_strip = file::should_strip_components(archive_path, format)?; // Find executable files diff --git a/src/file.rs b/src/file.rs index caa85388ce..97318c266d 100644 --- a/src/file.rs +++ b/src/file.rs @@ -912,7 +912,7 @@ pub fn un_bz2(input: &Path, dest: &Path) -> Result<()> { Ok(()) } -pub fn decompress_file(input: &Path, dest: &Path, format: TarFormat) -> Result<()> { +pub fn decompress_file(input: &Path, dest: &Path, format: ExtractionFormat) -> Result<()> { if let Some(parent) = dest.parent() && !parent.as_os_str().is_empty() { @@ -920,16 +920,16 @@ pub fn decompress_file(input: &Path, dest: &Path, format: TarFormat) -> Result<( } match format { - TarFormat::Gz => un_gz(input, dest), - TarFormat::Xz => un_xz(input, dest), - TarFormat::Zst => un_zst(input, dest), - TarFormat::Bz2 => un_bz2(input, dest), + ExtractionFormat::Gz => un_gz(input, dest), + ExtractionFormat::Xz => un_xz(input, dest), + ExtractionFormat::Zst => un_zst(input, dest), + ExtractionFormat::Bz2 => un_bz2(input, dest), _ => bail!("unsupported compressed file format: {}", format), } } #[derive(Debug, Clone, Copy, PartialEq, strum::EnumString, strum::Display)] -pub enum TarFormat { +pub enum ExtractionFormat { #[strum(serialize = "tar.gz", serialize = "tgz")] TarGz, #[strum(serialize = "gz")] @@ -956,14 +956,14 @@ pub enum TarFormat { Raw, } -impl TarFormat { +impl ExtractionFormat { pub fn from_file_name(filename: &str) -> Self { let filename = filename.to_lowercase(); if let Some(idx) = filename.rfind(".tar.") { let ext = &filename[idx + 1..]; let fmt = Self::from_ext(ext); - if fmt != TarFormat::Raw { + if fmt != ExtractionFormat::Raw { return fmt; } } @@ -971,50 +971,53 @@ impl TarFormat { if let Some(ext) = Path::new(&filename).extension().and_then(|s| s.to_str()) { Self::from_ext(ext) } else { - TarFormat::Raw + ExtractionFormat::Raw } } pub fn from_ext(ext: &str) -> Self { - ext.to_lowercase().parse().unwrap_or(TarFormat::Raw) + ext.to_lowercase().parse().unwrap_or(ExtractionFormat::Raw) } pub fn is_archive(&self) -> bool { - self.is_tar_archive() || matches!(self, TarFormat::Zip | TarFormat::SevenZip) + self.is_tar_archive() || matches!(self, ExtractionFormat::Zip | ExtractionFormat::SevenZip) } pub fn is_tar_archive(&self) -> bool { matches!( self, - TarFormat::TarGz - | TarFormat::TarXz - | TarFormat::TarBz2 - | TarFormat::TarZst - | TarFormat::Tar + ExtractionFormat::TarGz + | ExtractionFormat::TarXz + | ExtractionFormat::TarBz2 + | ExtractionFormat::TarZst + | ExtractionFormat::Tar ) } pub fn is_compressed_file(&self) -> bool { matches!( self, - TarFormat::Gz | TarFormat::Xz | TarFormat::Bz2 | TarFormat::Zst + ExtractionFormat::Gz + | ExtractionFormat::Xz + | ExtractionFormat::Bz2 + | ExtractionFormat::Zst ) } pub fn extension(&self) -> Option<&'static str> { match self { - TarFormat::TarGz => Some("tar.gz"), - TarFormat::Gz => Some("gz"), - TarFormat::TarXz => Some("tar.xz"), - TarFormat::Xz => Some("xz"), - TarFormat::TarBz2 => Some("tar.bz2"), - TarFormat::Bz2 => Some("bz2"), - TarFormat::TarZst => Some("tar.zst"), - TarFormat::Zst => Some("zst"), - TarFormat::Tar => Some("tar"), - TarFormat::Zip => Some("zip"), - TarFormat::SevenZip => Some("7z"), - TarFormat::Raw => None, + ExtractionFormat::TarGz => Some("tar.gz"), + ExtractionFormat::Gz => Some("gz"), + ExtractionFormat::TarXz => Some("tar.xz"), + ExtractionFormat::Xz => Some("xz"), + ExtractionFormat::TarBz2 => Some("tar.bz2"), + ExtractionFormat::Bz2 => Some("bz2"), + ExtractionFormat::TarZst => Some("tar.zst"), + ExtractionFormat::Zst => Some("zst"), + ExtractionFormat::Tar => Some("tar"), + ExtractionFormat::Zip => Some("zip"), + ExtractionFormat::SevenZip => Some("7z"), + ExtractionFormat::Raw => None, } } } @@ -1039,18 +1042,18 @@ impl<'a> Default for ExtractOptions<'a> { pub fn extract_archive( archive: &Path, dest: &Path, - format: TarFormat, + format: ExtractionFormat, opts: &ExtractOptions, ) -> Result<()> { match format { - TarFormat::TarGz - | TarFormat::TarXz - | TarFormat::TarBz2 - | TarFormat::TarZst - | TarFormat::Tar - | TarFormat::Raw => untar(archive, dest, format, opts), - TarFormat::Zip => unzip(archive, dest, opts), - TarFormat::SevenZip => { + ExtractionFormat::TarGz + | ExtractionFormat::TarXz + | ExtractionFormat::TarBz2 + | ExtractionFormat::TarZst + | ExtractionFormat::Tar + | ExtractionFormat::Raw => untar(archive, dest, format, opts), + ExtractionFormat::Zip => unzip(archive, dest, opts), + ExtractionFormat::SevenZip => { #[cfg(windows)] { return un7z(archive, dest, opts); @@ -1060,14 +1063,22 @@ pub fn extract_archive( bail!("7z format not supported on this platform"); } } - TarFormat::Gz | TarFormat::Xz | TarFormat::Bz2 | TarFormat::Zst => { + ExtractionFormat::Gz + | ExtractionFormat::Xz + | ExtractionFormat::Bz2 + | ExtractionFormat::Zst => { bail!("extract_archive does not support compressed single-file format: {format}") } } } -pub fn untar(archive: &Path, dest: &Path, format: TarFormat, opts: &ExtractOptions) -> Result<()> { - if !format.is_tar_archive() && format != TarFormat::Raw { +pub fn untar( + archive: &Path, + dest: &Path, + format: ExtractionFormat, + opts: &ExtractOptions, +) -> Result<()> { + if !format.is_tar_archive() && format != ExtractionFormat::Raw { bail!("untar only supports tar formats, got {}", format); } @@ -1166,20 +1177,23 @@ pub fn untar(archive: &Path, dest: &Path, format: TarFormat, opts: &ExtractOptio Ok(()) } -fn open_tar(format: TarFormat, archive: &Path) -> Result> { +fn open_tar(format: ExtractionFormat, archive: &Path) -> Result> { let f = File::open(archive)?; Ok(match format { // TODO: we probably shouldn't assume raw is tar.gz, but this was to retain existing behavior - TarFormat::TarGz | TarFormat::Raw => Box::new(GzDecoder::new(f)), - TarFormat::TarXz => Box::new(xz2::read::XzDecoder::new(f)), - TarFormat::TarBz2 => Box::new(BzDecoder::new(f)), - TarFormat::TarZst => Box::new(zstd::stream::read::Decoder::new(f)?), - TarFormat::Tar => Box::new(f), - TarFormat::Gz | TarFormat::Xz | TarFormat::Bz2 | TarFormat::Zst => { + ExtractionFormat::TarGz | ExtractionFormat::Raw => Box::new(GzDecoder::new(f)), + ExtractionFormat::TarXz => Box::new(xz2::read::XzDecoder::new(f)), + ExtractionFormat::TarBz2 => Box::new(BzDecoder::new(f)), + ExtractionFormat::TarZst => Box::new(zstd::stream::read::Decoder::new(f)?), + ExtractionFormat::Tar => Box::new(f), + ExtractionFormat::Gz + | ExtractionFormat::Xz + | ExtractionFormat::Bz2 + | ExtractionFormat::Zst => { bail!("{} is not a tar archive", format) } - TarFormat::Zip => bail!("zip format not supported"), - TarFormat::SevenZip => bail!("7z format not supported"), + ExtractionFormat::Zip => bail!("zip format not supported"), + ExtractionFormat::SevenZip => bail!("7z format not supported"), }) } @@ -1353,7 +1367,10 @@ fn skip_curdir_components(path: &Path) -> impl Iterator Result> { +pub fn inspect_tar_contents( + archive: &Path, + format: ExtractionFormat, +) -> Result> { let tar = open_tar(format, archive)?; let mut archive = Archive::new(tar); let mut top_level_components = std::collections::HashMap::new(); @@ -1443,10 +1460,10 @@ pub fn inspect_7z_contents(_archive: &Path) -> Result> { } /// Determines if strip_components=1 should be applied based on archive structure -pub fn should_strip_components(archive: &Path, format: TarFormat) -> Result { +pub fn should_strip_components(archive: &Path, format: ExtractionFormat) -> Result { let top_level_entries = match format { - TarFormat::Zip => inspect_zip_contents(archive)?, - TarFormat::SevenZip => inspect_7z_contents(archive)?, + ExtractionFormat::Zip => inspect_zip_contents(archive)?, + ExtractionFormat::SevenZip => inspect_7z_contents(archive)?, _ => inspect_tar_contents(archive, format)?, }; @@ -1473,7 +1490,7 @@ pub struct ArchiveContent { /// fail closed instead of being ignored. pub fn archive_content_files( archive_path: &Path, - format: TarFormat, + format: ExtractionFormat, strip_components: usize, ) -> Result> { if strip_components > 1 { @@ -1481,16 +1498,22 @@ pub fn archive_content_files( } match format { - TarFormat::TarGz - | TarFormat::TarXz - | TarFormat::TarBz2 - | TarFormat::TarZst - | TarFormat::Tar => archive_content_files_tar(archive_path, format, strip_components), - TarFormat::Zip => archive_content_files_zip(archive_path, strip_components), - TarFormat::SevenZip => { + ExtractionFormat::TarGz + | ExtractionFormat::TarXz + | ExtractionFormat::TarBz2 + | ExtractionFormat::TarZst + | ExtractionFormat::Tar => { + archive_content_files_tar(archive_path, format, strip_components) + } + ExtractionFormat::Zip => archive_content_files_zip(archive_path, strip_components), + ExtractionFormat::SevenZip => { bail!("content-level SLSA verification does not support 7z archives") } - TarFormat::Gz | TarFormat::Xz | TarFormat::Bz2 | TarFormat::Zst | TarFormat::Raw => { + ExtractionFormat::Gz + | ExtractionFormat::Xz + | ExtractionFormat::Bz2 + | ExtractionFormat::Zst + | ExtractionFormat::Raw => { bail!("content-level SLSA verification only supports archive formats") } } @@ -1498,7 +1521,7 @@ pub fn archive_content_files( fn archive_content_files_tar( archive_path: &Path, - format: TarFormat, + format: ExtractionFormat, strip_components: usize, ) -> Result> { let tar = open_tar(format, archive_path)?; @@ -1645,7 +1668,7 @@ mod tests { builder.finish().unwrap(); } - let files = archive_content_files(&archive_path, TarFormat::Tar, 1).unwrap(); + let files = archive_content_files(&archive_path, ExtractionFormat::Tar, 1).unwrap(); assert_eq!(files.len(), 1); assert_eq!(files[0].name, "tool"); assert_eq!(files[0].sha256, hex::encode(Sha256::digest(b"tool"))); @@ -1669,7 +1692,7 @@ mod tests { builder.finish().unwrap(); } - let err = archive_content_files(&archive_path, TarFormat::Tar, 0).unwrap_err(); + let err = archive_content_files(&archive_path, ExtractionFormat::Tar, 0).unwrap_err(); assert!(err.to_string().contains("non-regular archive entry")); } @@ -1782,7 +1805,7 @@ mod tests { // For now, we'll test with a nonexistent file to ensure the function // returns false when it can't read the archive let non_existent_path = Path::new("/non/existent/archive.tar.gz"); - let result = should_strip_components(non_existent_path, TarFormat::TarGz); + let result = should_strip_components(non_existent_path, ExtractionFormat::TarGz); assert!(result.is_err()); // Should fail to open nonexistent file // Note: To properly test this function, we would need actual tar archives @@ -1859,7 +1882,7 @@ mod tests { gz.finish().unwrap(); // Now test inspect_tar_contents - let result = inspect_tar_contents(temp_file.path(), TarFormat::TarGz).unwrap(); + let result = inspect_tar_contents(temp_file.path(), ExtractionFormat::TarGz).unwrap(); // Should have 3 top-level entries: dir1, dir2, standalone // NOT a single "." entry @@ -1886,7 +1909,8 @@ mod tests { } // Verify should_strip_components returns false (multiple top-level entries) - let should_strip = should_strip_components(temp_file.path(), TarFormat::TarGz).unwrap(); + let should_strip = + should_strip_components(temp_file.path(), ExtractionFormat::TarGz).unwrap(); assert!( !should_strip, "Should NOT strip components for multi-entry archive" @@ -1959,25 +1983,79 @@ mod tests { } #[test] - fn test_archive_format_from_file_name() { - assert_eq!(TarFormat::from_file_name("foo.tar.gz"), TarFormat::TarGz); - assert_eq!(TarFormat::from_file_name("foo.tgz"), TarFormat::TarGz); - assert_eq!(TarFormat::from_file_name("foo.tar.xz"), TarFormat::TarXz); - assert_eq!(TarFormat::from_file_name("foo.txz"), TarFormat::TarXz); - assert_eq!(TarFormat::from_file_name("foo.tar.bz2"), TarFormat::TarBz2); - assert_eq!(TarFormat::from_file_name("foo.tbz2"), TarFormat::TarBz2); - assert_eq!(TarFormat::from_file_name("foo.tar.zst"), TarFormat::TarZst); - assert_eq!(TarFormat::from_file_name("foo.tzst"), TarFormat::TarZst); - assert_eq!(TarFormat::from_file_name("foo.tar"), TarFormat::Tar); - assert_eq!(TarFormat::from_file_name("foo.zip"), TarFormat::Zip); - assert_eq!(TarFormat::from_file_name("foo.vsix"), TarFormat::Zip); - assert_eq!(TarFormat::from_file_name("foo.7z"), TarFormat::SevenZip); - assert_eq!(TarFormat::from_file_name("foo.gz"), TarFormat::Gz); - assert_eq!(TarFormat::from_file_name("foo.xz"), TarFormat::Xz); - assert_eq!(TarFormat::from_file_name("foo.bz2"), TarFormat::Bz2); - assert_eq!(TarFormat::from_file_name("foo.zst"), TarFormat::Zst); - assert_eq!(TarFormat::from_file_name("foo"), TarFormat::Raw); - assert_eq!(TarFormat::from_file_name("foo.txt"), TarFormat::Raw); + fn test_extraction_format_from_file_name() { + assert_eq!( + ExtractionFormat::from_file_name("foo.tar.gz"), + ExtractionFormat::TarGz + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tgz"), + ExtractionFormat::TarGz + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tar.xz"), + ExtractionFormat::TarXz + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.txz"), + ExtractionFormat::TarXz + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tar.bz2"), + ExtractionFormat::TarBz2 + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tbz2"), + ExtractionFormat::TarBz2 + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tar.zst"), + ExtractionFormat::TarZst + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tzst"), + ExtractionFormat::TarZst + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.tar"), + ExtractionFormat::Tar + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.zip"), + ExtractionFormat::Zip + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.vsix"), + ExtractionFormat::Zip + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.7z"), + ExtractionFormat::SevenZip + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.gz"), + ExtractionFormat::Gz + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.xz"), + ExtractionFormat::Xz + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.bz2"), + ExtractionFormat::Bz2 + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.zst"), + ExtractionFormat::Zst + ); + assert_eq!( + ExtractionFormat::from_file_name("foo"), + ExtractionFormat::Raw + ); + assert_eq!( + ExtractionFormat::from_file_name("foo.txt"), + ExtractionFormat::Raw + ); } #[test] @@ -1996,7 +2074,7 @@ mod tests { encoder.write_all(b"hello world").unwrap(); encoder.finish().unwrap(); - decompress_file(&src_path, &dest_path, TarFormat::Gz).unwrap(); + decompress_file(&src_path, &dest_path, ExtractionFormat::Gz).unwrap(); assert!(dest_path.exists()); assert!(dest_path.is_file()); @@ -2020,7 +2098,7 @@ mod tests { encoder.write_all(b"hello world").unwrap(); encoder.finish().unwrap(); - decompress_file(&src_path, &dest_path, TarFormat::Gz).unwrap(); + decompress_file(&src_path, &dest_path, ExtractionFormat::Gz).unwrap(); assert!(dest_path.exists()); assert!(dest_path.is_file()); @@ -2047,7 +2125,7 @@ mod tests { extract_archive( &src_path, &dest_dir, - TarFormat::Zip, + ExtractionFormat::Zip, &ExtractOptions::default(), ) .unwrap(); @@ -2069,7 +2147,7 @@ mod tests { let err = untar( &src_path, &dest_path, - TarFormat::Gz, + ExtractionFormat::Gz, &ExtractOptions::default(), ) .unwrap_err(); @@ -2086,7 +2164,7 @@ mod tests { use tempfile::NamedTempFile; let archive = NamedTempFile::new().unwrap(); - let err = should_strip_components(archive.path(), TarFormat::SevenZip).unwrap_err(); + let err = should_strip_components(archive.path(), ExtractionFormat::SevenZip).unwrap_err(); assert!( format!("{err:#}").contains("7z format not supported on this platform"), diff --git a/src/plugins/asdf_plugin.rs b/src/plugins/asdf_plugin.rs index 016e92fa6f..e38ec6a30e 100644 --- a/src/plugins/asdf_plugin.rs +++ b/src/plugins/asdf_plugin.rs @@ -192,7 +192,8 @@ impl AsdfPlugin { pr.set_message("extracting zip file".to_string()); - let strip_components = file::should_strip_components(&temp_archive, file::TarFormat::Zip)?; + let strip_components = + file::should_strip_components(&temp_archive, file::ExtractionFormat::Zip)?; file::unzip( &temp_archive, diff --git a/src/plugins/core/erlang.rs b/src/plugins/core/erlang.rs index d17852bb34..70a5a20d68 100644 --- a/src/plugins/core/erlang.rs +++ b/src/plugins/core/erlang.rs @@ -147,7 +147,7 @@ impl ErlangPlugin { file::untar( &tarball_path, &tv.download_path(), - file::TarFormat::TarGz, + file::ExtractionFormat::TarGz, &ExtractOptions { pr: Some(ctx.pr.as_ref()), ..Default::default() @@ -235,7 +235,7 @@ impl ErlangPlugin { file::untar( &tarball_path, &tv.install_path(), - file::TarFormat::TarGz, + file::ExtractionFormat::TarGz, &ExtractOptions { pr: Some(ctx.pr.as_ref()), ..Default::default() diff --git a/src/plugins/core/go.rs b/src/plugins/core/go.rs index e11f323301..da871c1f61 100644 --- a/src/plugins/core/go.rs +++ b/src/plugins/core/go.rs @@ -8,7 +8,7 @@ use crate::backend::{Backend, VersionInfo}; use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::http::HTTP; use crate::install_context::InstallContext; use crate::lockfile::PlatformInfo; @@ -160,7 +160,7 @@ impl GoPlugin { file::untar( tarball_path, tmp_extract_path.path(), - TarFormat::TarGz, + ExtractionFormat::TarGz, &ExtractOptions { pr: Some(pr), ..Default::default() diff --git a/src/plugins/core/java.rs b/src/plugins/core/java.rs index 588f790b7e..4731324fe4 100644 --- a/src/plugins/core/java.rs +++ b/src/plugins/core/java.rs @@ -13,7 +13,7 @@ use crate::cli::args::BackendArg; use crate::cli::version::OS; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; use crate::lockfile::PlatformInfo; @@ -232,9 +232,9 @@ impl JavaPlugin { let format = m .file_type .as_deref() - .map(TarFormat::from_ext) - .filter(|f| *f != TarFormat::Raw) - .unwrap_or_else(|| TarFormat::from_file_name(&filename)); + .map(ExtractionFormat::from_ext) + .filter(|f| *f != ExtractionFormat::Raw) + .unwrap_or_else(|| ExtractionFormat::from_file_name(&filename)); file::extract_archive( tarball_path, &tv.download_path(), diff --git a/src/plugins/core/node.rs b/src/plugins/core/node.rs index ce02bdec0c..c52356fa86 100644 --- a/src/plugins/core/node.rs +++ b/src/plugins/core/node.rs @@ -9,7 +9,7 @@ use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::settings::DEFAULT_NODE_MIRROR_URL; use crate::config::{Config, Settings}; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; use crate::lockfile::PlatformInfo; @@ -116,7 +116,7 @@ impl NodePlugin { file::untar( &opts.binary_tarball_path, &opts.install_path, - TarFormat::TarGz, + ExtractionFormat::TarGz, &ExtractOptions { strip_components: 1, pr: Some(ctx.pr.as_ref()), @@ -188,7 +188,7 @@ impl NodePlugin { file::untar( &opts.source_tarball_path, opts.build_dir.parent().unwrap(), - TarFormat::TarGz, + ExtractionFormat::TarGz, &ExtractOptions { pr: Some(ctx.pr.as_ref()), ..Default::default() diff --git a/src/plugins/core/python.rs b/src/plugins/core/python.rs index ca574d8493..8501dac4eb 100644 --- a/src/plugins/core/python.rs +++ b/src/plugins/core/python.rs @@ -7,7 +7,7 @@ use crate::cache::{CacheManager, CacheManagerBuilder}; use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::file::{ExtractOptions, TarFormat, display_path}; +use crate::file::{ExtractOptions, ExtractionFormat, display_path}; use crate::git::{CloneOptions, Git}; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; @@ -373,7 +373,7 @@ impl PythonPlugin { file::extract_archive( &tarball_path, &install, - TarFormat::from_file_name(filename), + ExtractionFormat::from_file_name(filename), &ExtractOptions { strip_components: 1, pr: Some(ctx.pr.as_ref()), diff --git a/src/plugins/core/ruby.rs b/src/plugins/core/ruby.rs index d5e748f381..cd379ecbd4 100644 --- a/src/plugins/core/ruby.rs +++ b/src/plugins/core/ruby.rs @@ -187,7 +187,7 @@ impl RubyPlugin { } let strip_components = - file::should_strip_components(&temp_archive, file::TarFormat::Zip)?; + file::should_strip_components(&temp_archive, file::ExtractionFormat::Zip)?; file::unzip( &temp_archive, @@ -794,7 +794,7 @@ impl RubyPlugin { file::untar( &tarball_path, &install_path, - file::TarFormat::TarGz, + file::ExtractionFormat::TarGz, &file::ExtractOptions { strip_components: 1, pr: Some(ctx.pr.as_ref()), diff --git a/src/plugins/core/swift.rs b/src/plugins/core/swift.rs index b7862b37ef..64c0f92566 100644 --- a/src/plugins/core/swift.rs +++ b/src/plugins/core/swift.rs @@ -92,7 +92,7 @@ impl SwiftPlugin { file::untar( tarball_path, &tv.install_path(), - file::TarFormat::TarGz, + file::ExtractionFormat::TarGz, &file::ExtractOptions { strip_components: 1, pr: Some(ctx.pr.as_ref()), diff --git a/src/plugins/core/zig.rs b/src/plugins/core/zig.rs index 5c1fbea3ac..9083106c5a 100644 --- a/src/plugins/core/zig.rs +++ b/src/plugins/core/zig.rs @@ -11,7 +11,7 @@ use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; use crate::duration::DAILY; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; use crate::lockfile::{PlatformInfo, ProvenanceType}; @@ -141,7 +141,7 @@ impl ZigPlugin { file::extract_archive( tarball_path, &tv.install_path(), - TarFormat::from_file_name(&filename), + ExtractionFormat::from_file_name(&filename), &ExtractOptions { strip_components: 1, pr: Some(ctx.pr.as_ref()), diff --git a/src/plugins/vfox_plugin.rs b/src/plugins/vfox_plugin.rs index bdc5ec8be5..8670dfb6f9 100644 --- a/src/plugins/vfox_plugin.rs +++ b/src/plugins/vfox_plugin.rs @@ -159,7 +159,8 @@ impl VfoxPlugin { pr.set_message("extracting zip file".to_string()); - let strip_components = file::should_strip_components(&temp_archive, file::TarFormat::Zip)?; + let strip_components = + file::should_strip_components(&temp_archive, file::ExtractionFormat::Zip)?; file::unzip( &temp_archive, diff --git a/src/system/packages/brew/cask.rs b/src/system/packages/brew/cask.rs index 3ac0e14939..6d84d479df 100644 --- a/src/system/packages/brew/cask.rs +++ b/src/system/packages/brew/cask.rs @@ -7,7 +7,7 @@ use serde_json::Value; use walkdir::WalkDir; use super::prefix; -use crate::file::{self, ExtractOptions, TarFormat}; +use crate::file::{self, ExtractOptions, ExtractionFormat}; use crate::hash; use crate::http::HTTP_FETCH; use crate::result::Result; @@ -231,7 +231,7 @@ fn extract_archive(cask: &Cask, archive: &Path, pr: Option<&dyn SingleReport>) - if filename.ends_with(".dmg") { file::un_dmg(archive, &extract_dir)?; } else { - let format = TarFormat::from_file_name(filename); + let format = ExtractionFormat::from_file_name(filename); if !format.is_archive() { bail!( "brew-cask:{}: unsupported archive type for {}", diff --git a/src/system/packages/brew/pour.rs b/src/system/packages/brew/pour.rs index b5ccc606bd..cf88794425 100644 --- a/src/system/packages/brew/pour.rs +++ b/src/system/packages/brew/pour.rs @@ -9,7 +9,7 @@ use super::api::BottleFile; use super::prefix; use super::relocate; use super::resolve::ResolvedFormula; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::result::Result; use crate::ui::progress_report::SingleReport; @@ -93,7 +93,7 @@ pub async fn pour( crate::file::untar( tarball, &scratch, - TarFormat::TarGz, + ExtractionFormat::TarGz, &ExtractOptions { strip_components: 0, pr: Some(pr), diff --git a/src/system/packages/brew/source.rs b/src/system/packages/brew/source.rs index 950aae18be..0abb9d7c14 100644 --- a/src/system/packages/brew/source.rs +++ b/src/system/packages/brew/source.rs @@ -21,7 +21,7 @@ use super::resolve::ResolvedFormula; use super::tag; use crate::cmd::CmdLineRunner; use crate::config::{Config, Settings}; -use crate::file::{ExtractOptions, TarFormat}; +use crate::file::{ExtractOptions, ExtractionFormat}; use crate::http::HTTP_FETCH; use crate::result::Result; use crate::toolset::{InstallOptions, ToolsetBuilder}; @@ -275,7 +275,7 @@ fn stage_source(archive: &Path, build_root: &Path, basename: &str) -> Result