Skip to content

Commit

Permalink
archive: switch to deko AnyDecoder and support tar.xz
Browse files Browse the repository at this point in the history
  • Loading branch information
hdhoang committed Jan 10, 2025
1 parent 41ad6c3 commit d54ea11
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
47 changes: 46 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ zip = { version = "2.2.2", default-features = false, features = ["deflate"] }
clap_complete = "4.5.42"
console = "0.15.10"
dirs = "5.0.1"
flate2 = "1.0"
indicatif = "0.17.9"
shellexpand = "3.1.0"
tar = "0.4.43"
tempdir = "0.3.7"
toml = "0.8.19"
deko = { version = "0", default-features = false, features = ["flate2", "xz"] }
31 changes: 19 additions & 12 deletions src/sync/archive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use flate2::read::GzDecoder;
use deko::AnyDecoder;
use std::fmt::{Display, Formatter};
use std::fs::File;
use std::io::BufReader;
use std::path::{Path, PathBuf};

use crate::model::asset_name::mk_exe_name;
Expand All @@ -18,7 +19,7 @@ enum ArchiveType<'a> {
AppImage(&'a str),
Exe(&'a str),
Zip(&'a str),
TarGz(&'a str),
TarBall(&'a str),
}

pub enum UnpackError {
Expand Down Expand Up @@ -89,7 +90,7 @@ impl<'a> Archive<'a> {
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::TarGz(prefix),
archive_type: ArchiveType::TarBall(prefix),
}
.into()
}
Expand All @@ -103,14 +104,19 @@ impl<'a> Archive<'a> {
}
.into()
}
_ => {
asset_name.strip_suffix(".tar.gz").map(|tar_gz_dir| Archive {
archive_path,
tmp_dir,
exe_name,
Some((prefix, "xz"|"gz")) => {
return Archive {
archive_path,
tmp_dir,
exe_name,
tag,
archive_type: ArchiveType::TarGz(tar_gz_dir),
})
archive_type: ArchiveType::TarBall(prefix.trim_end_matches(".tar")),
}
.into()
}
_ => {
dbg!("unsupported asset format {asset_name}");
return None
}
}
}
Expand All @@ -125,7 +131,7 @@ impl<'a> Archive<'a> {
ArchiveType::Exe(exe_file) => Ok(self.tmp_dir.join(exe_file)),

// unpack .tar.gz archive
ArchiveType::TarGz(asset_name) => {
ArchiveType::TarBall(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, self.tag)
}
Expand All @@ -145,7 +151,7 @@ fn unpack_tar(
) -> Result<(), std::io::Error> {
// unpack tar_path to tmp_dir
let tar_file = File::open(tar_path)?;
let tar_decoder = GzDecoder::new(tar_file);
let tar_decoder = AnyDecoder::new(BufReader::new(tar_file));
let mut archive = tar::Archive::new(tar_decoder);
archive.unpack(tmp_dir)
}
Expand Down Expand Up @@ -199,6 +205,7 @@ fn exe_paths(

vec![
asset_name.into(),
asset_name.trim_end_matches(".tar.xz").into(),
asset_name.trim_end_matches(".tar.gz").into(),
asset_name.trim_end_matches(".tgz").into(),
asset_name.trim_end_matches(".zip").into(),
Expand Down

0 comments on commit d54ea11

Please sign in to comment.