Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions src/backend/aqua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1302,7 +1302,7 @@ impl AquaBackend {
v: &str,
) -> Result<bool> {
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"
Expand Down Expand Up @@ -2295,17 +2295,21 @@ impl AquaBackend {
}
}

fn effective_archive_format(pkg: &AquaPackage, format: &str) -> Result<TarFormat> {
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<ExtractionFormat> {
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)
}
}

Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/backend/asset_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) ==========
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,9 +1989,9 @@ impl UnifiedGitBackend {
) -> Result<bool> {
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(),
)
};
Expand Down
12 changes: 6 additions & 6 deletions src/backend/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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()
Expand All @@ -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;

Comment thread
risu729 marked this conversation as resolved.
Self {
effective_path,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/backend/static_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,20 @@ 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(),
)
};

// 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()
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/cli/generate/tool_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
Loading
Loading