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
182 changes: 29 additions & 153 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ fs4 = "0.7.0"
flate2 = "1.0.30"
tar = "0.4.41"
zip = "8.3.0"
zip-extract = "0.1.3"
xz2 = "0.1.7"
liblzma = "0.4.1"
signal-hook = "0.3.17"
nix = { version = "0.29.0", features = ["signal"] }
serde = { version = "1.0.204", features = ["derive"] }
Expand Down
24 changes: 12 additions & 12 deletions src/adapters/archive.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::fs;
use std::io;
use std::path::Path;

use anyhow::anyhow;
use anyhow::Result;
use xz2::read::XzDecoder;
use zip_extract::extract;
use liblzma::read::XzDecoder;
use zip::ZipArchive as ZipReader;

use crate::domain::package::Package;
use crate::domain::version::LocalVersion;
Expand Down Expand Up @@ -52,25 +50,27 @@ fn expand(package: Package, tmp: LocalVersion) -> Result<()> {
})?;

let output = format!("{}/{}", tmp.path, tmp.file_name);
let decompress_stream: Box<dyn std::io::Read> = match tmp.file_format.as_str() {
"tar.gz" => Box::new(GzDecoder::new(&file)),
"tar.xz" => Box::new(XzDecoder::new(&file)),
"zip" => Box::new(io::empty()),
_ => return Err(anyhow!("Unsupported file format")),
};

let context_msg = format!(
"Failed to decompress or extract file {}.{}",
tmp.file_name, tmp.file_format
);

match tmp.file_format.as_str() {
"tar.gz" | "tar.xz" => {
"tar.gz" => {
let decompress_stream = GzDecoder::new(file);
let mut archive = Archive::new(decompress_stream);
archive.unpack(&output).with_context(|| context_msg)?;
}
"tar.xz" => {
let decompress_stream = XzDecoder::new(file);
let mut archive = Archive::new(decompress_stream);
archive.unpack(&output).with_context(|| context_msg)?;
}
"zip" => {
extract(&file, Path::new(&output), true).with_context(|| context_msg)?;
let mut archive = ZipReader::new(file)
.map_err(|error| anyhow!("{context_msg}. additional info: {error}"))?;
archive.extract(&output).with_context(|| context_msg)?;
}
_ => return Err(anyhow!("Unsupported file format")),
}
Expand Down
Loading