Skip to content
Merged
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
44 changes: 41 additions & 3 deletions src/backend/asset_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,15 @@ impl AssetPicker {
}

if format.is_archive() {
return 10;
return match format {
// Since we are downloading, prefer small archives: zstd and xz
// tend to be smaller archives.
ExtractionFormat::TarZst => 15,
// xz comes in after zst because it can cost more CPU to decompress.
ExtractionFormat::TarXz => 13,
// All other archive formats roughly created equal.
_ => 10,
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

// Platform-agnostic runtime archives (composer.phar, foo.jar, bar.pyz)
Expand Down Expand Up @@ -744,8 +752,8 @@ fn asset_matches_preferred_name(asset: &str, preferred_name: &str) -> bool {
fn asset_name_stem(asset: &str) -> String {
let mut name = asset.rsplit('/').next().unwrap_or(asset).to_lowercase();
let suffixes = [
".tar.gz", ".tar.xz", ".tar.bz2", ".tar.zst", ".tgz", ".tar", ".zip", ".gz", ".xz", ".bz2",
".zst", ".phar", ".jar", ".pyz", ".exe", ".msi",
".tar.gz", ".tar.xz", ".tar.bz2", ".tar.zst", ".tgz", ".txz", ".tzst", ".tar", ".zip",
".gz", ".xz", ".bz2", ".zst", ".phar", ".jar", ".pyz", ".exe", ".msi",
];

if let Some(suffix) = suffixes.iter().find(|suffix| name.ends_with(*suffix)) {
Expand Down Expand Up @@ -1690,6 +1698,36 @@ abc123def456abc123def456abc123def456abc123def456abc123def456abcd tool-1.0.0-dar
assert_eq!(picked, "tool-1.0.0-linux-x86_64.tar.gz");
}

#[test]
fn test_archive_format_preference_order() {
let picker = AssetPicker::with_libc("linux".to_string(), "x86_64".to_string(), None);
let tar_zst = "tool-1.0.0-linux-x86_64.tar.zst";
let tar_xz = "tool-1.0.0-linux-x86_64.tar.xz";
let tar_gz = "tool-1.0.0-linux-x86_64.tar.gz";

let picked = picker
.pick_best_asset(&[tar_gz.to_string(), tar_xz.to_string(), tar_zst.to_string()])
.unwrap();
assert_eq!(picked, tar_zst);

let picked = picker
.pick_best_asset(&[tar_gz.to_string(), tar_xz.to_string()])
.unwrap();
assert_eq!(picked, tar_xz);
}

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
#[test]
fn test_asset_name_stem_strips_shorthand_archive_suffixes() {
assert_eq!(
asset_name_stem("tool-1.0.0-linux-x86_64.tzst"),
"tool-1.0.0-linux-x86_64"
);
assert_eq!(
asset_name_stem("tool-1.0.0-linux-x86_64.txz"),
"tool-1.0.0-linux-x86_64"
);
}

#[test]
fn test_platform_detection_from_url() {
// Test Node.js URL
Expand Down
Loading