Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bare executable artifacts #66

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions lib/sources/artifact/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum ArtifactFormat {
Zip,
Tar,
TarGz,
Pe,
Elf,
}

impl ArtifactFormat {
Expand All @@ -19,6 +21,8 @@ impl ArtifactFormat {
Self::Zip => "zip",
Self::Tar => "tar",
Self::TarGz => "tar.gz",
Self::Pe => "exe",
Self::Elf => "",
}
}

Expand All @@ -33,6 +37,8 @@ impl ArtifactFormat {
{
Some(Self::TarGz)
}
[.., ext] if ext.eq_ignore_ascii_case("exe") => Some(Self::Pe),
[""] => Some(Self::Elf),
_ => None,
}
}
Expand All @@ -53,6 +59,8 @@ impl FromStr for ArtifactFormat {
"zip" => Ok(Self::Zip),
"tar" => Ok(Self::Tar),
"tar.gz" | "tgz" => Ok(Self::TarGz),
"exe" => Ok(Self::Pe),
"bin" => Ok(Self::Elf),
_ => Err(format!("unknown artifact format '{l}'")),
}
}
Expand Down Expand Up @@ -94,8 +102,8 @@ mod tests {

#[test]
fn format_from_extensions_invalid() {
assert_eq!(format_from_str("file-name"), None);
assert_eq!(format_from_str("some/file.exe"), None);
assert_eq!(format_from_str("file-name.txt"), None);
assert_eq!(format_from_str("some/file.mp4"), None);
assert_eq!(format_from_str("really.long.file.name"), None);
}

Expand All @@ -117,6 +125,14 @@ mod tests {
format_from_str("sentry-cli-linux-i686-2.32.1.tgz"),
Some(ArtifactFormat::TarGz)
);
assert_eq!(
format_from_str("sentry-cli-Linux-x86_64"),
Some(ArtifactFormat::Elf)
);
assert_eq!(
format_from_str("sentry-cli-Windows-x86_64.exe"),
Some(ArtifactFormat::Pe)
);
}

#[test]
Expand All @@ -130,5 +146,8 @@ mod tests {
assert_eq!(format_from_str("file.tar.gz"), Some(ArtifactFormat::TarGz));
assert_eq!(format_from_str("file.TAR.GZ"), Some(ArtifactFormat::TarGz));
assert_eq!(format_from_str("file.Tar.Gz"), Some(ArtifactFormat::TarGz));
assert_eq!(format_from_str("file.exe"), Some(ArtifactFormat::Pe));
assert_eq!(format_from_str("file.EXE"), Some(ArtifactFormat::Pe));
assert_eq!(format_from_str("file"), Some(ArtifactFormat::Elf));
}
}
1 change: 1 addition & 0 deletions lib/sources/artifact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl Artifact {
let tar = decompress_gzip(&contents).await?;
extract_tar_file(&tar, &file_name).await
}
ArtifactFormat::Pe | ArtifactFormat::Elf => Ok(Some(contents.clone())),
};

// Make sure we got back the file we need ...
Expand Down
2 changes: 2 additions & 0 deletions lib/sources/artifact/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ mod tests {
test_some_mentions("selene-light-0.27.1-linux.zip", "selene");
// Valid - but multiple words
test_no_mentions("sentry-cli-linux-i686-2.32.1", "sentry-cli");
test_no_mentions("sentry-cli-Windows-i686.exe", "sentry-cli");
test_no_mentions("sentry-cli-Linux-i686", "sentry-cli");
test_no_mentions("selene-light-0.27.1-linux.zip", "selene-light");
}
}
37 changes: 24 additions & 13 deletions lib/sources/artifact/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

const ALLOWED_EXTENSION_NAMES: [&str; 4] = ["zip", "tar", "gz", "tgz"];
const ALLOWED_EXTENSION_NAMES: [&str; 6] = ["zip", "tar", "gz", "tgz", "exe", ""];
const ALLOWED_EXTENSION_COUNT: usize = 2;

pub(super) fn split_filename_and_extensions(name: &str) -> (&str, Vec<&str>) {
Expand All @@ -9,25 +9,36 @@ pub(super) fn split_filename_and_extensions(name: &str) -> (&str, Vec<&str>) {

// Reverse-pop extensions off the path until we reach the
// base name - we will then need to reverse afterwards, too
while let Some(ext) = path.extension() {
let ext = ext.to_str().expect("input was str");
let stem = path.file_stem().expect("had an extension");
loop {
if let Some(ext) = path.extension() {
let ext = ext.to_str().expect("input was str");
println!("Ext: {ext}");
let stem = path.file_stem().expect("had an extension");

if !ALLOWED_EXTENSION_NAMES
.iter()
.any(|e| e.eq_ignore_ascii_case(ext))
{
break;
}
if !ALLOWED_EXTENSION_NAMES
.iter()
.any(|e| e.eq_ignore_ascii_case(ext))
{
break;
}

exts.push(ext);
path = Path::new(stem);
exts.push(ext);
path = Path::new(stem);

if exts.len() >= ALLOWED_EXTENSION_COUNT {
if exts.len() >= ALLOWED_EXTENSION_COUNT {
break;
}
} else {
// Push an empty string if there are no more extensions in the path
exts.push("");
break;
}
}

if exts.len() > 1 && exts.contains(&"") {
exts.pop();
}

exts.reverse();

let path = path.to_str().expect("input was str");
Expand Down