Skip to content

Commit

Permalink
archive: detect orhun/binsider pattern
Browse files Browse the repository at this point in the history
Signed-off-by: Hoang Duc Hieu <[email protected]>
  • Loading branch information
hdhoang committed Oct 14, 2024
1 parent bdba8f7 commit 355e21f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/sync/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Archive<'a> {
archive_path: &'a PathBuf,
tmp_dir: &'a Path,
exe_name: &'a str,
tag: &'a str,
archive_type: ArchiveType<'a>,
}

Expand Down Expand Up @@ -47,6 +48,7 @@ impl<'a> Archive<'a> {
tmp_dir: &'a Path,
exe_name: &'a str,
asset_name: &'a str,
tag: &'a str,
) -> Option<Archive<'a>> {
match asset_name.rsplit_once('.') {
None | Some((_, "exe")) => {
Expand All @@ -55,6 +57,7 @@ impl<'a> Archive<'a> {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::Exe(asset_name),
}
.into();
Expand All @@ -65,6 +68,7 @@ impl<'a> Archive<'a> {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::Exe(asset_name),
}
.into();
Expand All @@ -74,6 +78,7 @@ impl<'a> Archive<'a> {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::AppImage(asset_name),
}
.into();
Expand All @@ -83,6 +88,7 @@ impl<'a> Archive<'a> {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::TarGz(prefix),
}
.into()
Expand All @@ -92,6 +98,7 @@ impl<'a> Archive<'a> {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::Zip(prefix),
}
.into()
Expand All @@ -101,6 +108,7 @@ impl<'a> Archive<'a> {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::TarGz(tar_gz_dir),
})
}
Expand All @@ -119,13 +127,13 @@ impl<'a> Archive<'a> {
// unpack .tar.gz archive
ArchiveType::TarGz(asset_name) => {
unpack_tar(self.archive_path, self.tmp_dir).map_err(UnpackError::IOError)?;
find_path_to_exe(self.archive_path, self.tmp_dir, self.exe_name, asset_name)
find_path_to_exe(self.archive_path, self.tmp_dir, self.exe_name, asset_name, self.tag)
}

// unpack .zip archive
ArchiveType::Zip(asset_name) => {
unpack_zip(self.archive_path, self.tmp_dir)?;
find_path_to_exe(self.archive_path, self.tmp_dir, self.exe_name, asset_name)
find_path_to_exe(self.archive_path, self.tmp_dir, self.exe_name, asset_name, self.tag)
}
}
}
Expand Down Expand Up @@ -158,8 +166,9 @@ fn find_path_to_exe(
tmp_dir: &Path,
exe_name: &str,
asset_name: &str,
tag: &str,
) -> Result<PathBuf, UnpackError> {
let path_candidates = exe_paths(exe_name, asset_name);
let path_candidates = exe_paths(exe_name, asset_name, tag);

// find a path
for path in path_candidates {
Expand All @@ -184,6 +193,7 @@ fn find_path_to_exe(
fn exe_paths(
exe_name: &str,
asset_name: &str,
tag: &str,
) -> Vec<PathBuf> {
let exe_name = mk_exe_name(exe_name);

Expand All @@ -199,5 +209,8 @@ fn exe_paths(
[&exe_name, &exe_name].iter().collect(),
["bin", &exe_name].iter().collect(),
[asset_name, "bin", &exe_name].iter().collect(),

[&format!("{exe_name}-{tag}"), &exe_name].iter().collect(),
[&format!("{exe_name}-{}", tag.trim_start_matches('v')), &exe_name].iter().collect(),
]
}
1 change: 1 addition & 0 deletions src/sync/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl<'a> Installer<'a> {
self.tmp_dir.path(),
&tool_asset.exe_name,
&tool_asset.asset.name,
&tool_asset.tag,
);

match archive {
Expand Down

0 comments on commit 355e21f

Please sign in to comment.