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
5 changes: 2 additions & 3 deletions src/backend/aqua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,11 +2297,10 @@ impl AquaBackend {

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")
{
if extraction_format.is_none() && !matches!(format, "" | "dmg" | "pkg") {
bail!("unsupported aqua package format: {format}");
}
let extraction_format = extraction_format.unwrap_or(ExtractionFormat::Raw);
if pkg.r#type == AquaPackageType::GithubArchive
&& extraction_format == ExtractionFormat::Raw
{
Expand Down
2 changes: 1 addition & 1 deletion src/backend/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ impl UnifiedGitBackend {
) -> Result<bool> {
let raw_opts = tv.request.options();
let format = if let Some(format_opt) = lookup_with_fallback(&raw_opts, "format") {
file::ExtractionFormat::from_ext(&format_opt)
file::ExtractionFormat::from_ext(&format_opt).unwrap_or(file::ExtractionFormat::Raw)
} else {
file::ExtractionFormat::from_file_name(
&file_path.file_name().unwrap_or_default().to_string_lossy(),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/static_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub fn install_artifact(
// 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::ExtractionFormat::from_ext(&format_opt)
file::ExtractionFormat::from_ext(&format_opt).unwrap_or(file::ExtractionFormat::Raw)
} else {
file::ExtractionFormat::from_file_name(
&file_path.file_name().unwrap_or_default().to_string_lossy(),
Expand Down
18 changes: 10 additions & 8 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,21 +979,20 @@ impl ExtractionFormat {

if let Some(idx) = filename.rfind(".tar.") {
let ext = &filename[idx + 1..];
let fmt = Self::from_ext(ext);
if fmt != ExtractionFormat::Raw {
if let Some(fmt) = Self::from_ext(ext) {
return fmt;
}
}

if let Some(ext) = Path::new(&filename).extension().and_then(|s| s.to_str()) {
Self::from_ext(ext)
Self::from_ext(ext).unwrap_or(ExtractionFormat::Raw)
} else {
ExtractionFormat::Raw
}
}

pub fn from_ext(ext: &str) -> Self {
ext.to_lowercase().parse().unwrap_or(ExtractionFormat::Raw)
pub fn from_ext(ext: &str) -> Option<Self> {
ext.to_lowercase().parse().ok()
}

pub fn is_archive(&self) -> bool {
Expand Down Expand Up @@ -2067,7 +2066,10 @@ mod tests {
ExtractionFormat::from_file_name("foo.tbz"),
ExtractionFormat::TarBz2
);
assert_eq!(ExtractionFormat::from_ext("tbz"), ExtractionFormat::TarBz2);
assert_eq!(
ExtractionFormat::from_ext("tbz"),
Some(ExtractionFormat::TarBz2)
);
assert_eq!(
ExtractionFormat::from_file_name("foo.tar.zst"),
ExtractionFormat::TarZst
Expand Down Expand Up @@ -2172,9 +2174,9 @@ mod tests {
("sz", ExtractionFormat::Sz),
("rar", ExtractionFormat::Rar),
] {
assert_eq!(ExtractionFormat::from_ext(ext), expected);
assert_ne!(ExtractionFormat::from_ext(ext), ExtractionFormat::Raw);
assert_eq!(ExtractionFormat::from_ext(ext), Some(expected));
}
assert_eq!(ExtractionFormat::from_ext("unknown"), None);

assert!(ExtractionFormat::TarBr.is_archive());
assert!(ExtractionFormat::TarLz4.is_archive());
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/core/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ impl JavaPlugin {
let format = m
.file_type
.as_deref()
.map(ExtractionFormat::from_ext)
.filter(|f| *f != ExtractionFormat::Raw)
.and_then(ExtractionFormat::from_ext)
.unwrap_or_else(|| ExtractionFormat::from_file_name(&filename));
file::extract_archive(
tarball_path,
Expand Down
Loading