Skip to content

Commit

Permalink
refactor: cleanup archive decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed May 6, 2024
1 parent 082e01b commit db150b1
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 113 deletions.
123 changes: 81 additions & 42 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions builder/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ impl BuildProcess {
/// `output_path` is the path at which the package's archive will be created.
pub fn create_archive(&self, output_path: &Path) -> io::Result<()> {
let build_desc_path = self.input_path.join("package.json");

let tar_gz = File::create(output_path)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.follow_symlinks(false);
tar.append_path_with_name(build_desc_path, "package.json")?;
tar.append_dir_all("data", &self.sysroot)?;
// TODO add install/update/remove hooks

tar.finish()
}

Expand Down
13 changes: 4 additions & 9 deletions builder/src/desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct Source {
}

impl Source {
/// Fetches files from the source and uncompresses them if necessary.
/// Fetches files from the source and decompress them if necessary.
///
/// Files are placed into the build directory `build_dir` according to the specified location.
pub async fn fetch(&self, build_dir: &Path) -> Result<()> {
Expand All @@ -75,9 +75,8 @@ impl Source {
if metadata.is_dir() {
common::util::recursive_copy(path, &dest_path)?;
} else {
// TODO uncompress only if it is an actual archive
// Uncompress tarball
common::util::uncompress(path, &dest_path, self.unwrap)?;
// TODO decompress only if it is an actual archive
common::util::decompress(path, &dest_path, self.unwrap)?;
}
}

Expand All @@ -97,12 +96,8 @@ impl Source {
let mut download_task = DownloadTask::new(url, &path).await?;
// TODO progress bar
while download_task.next().await? {}

// TODO check integrity with hash if specified

// Uncompress the archive
common::util::uncompress(&path, &dest_path, self.unwrap)?;

common::util::decompress(&path, &dest_path, self.unwrap)?;
// TODO remove archive?
}

Expand Down
2 changes: 1 addition & 1 deletion builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod util;

use crate::build::BuildProcess;
use crate::util::{get_build_triplet, get_jobs_count};
use anyhow::{anyhow, bail};
use anyhow::Result;
use anyhow::{anyhow, bail};
use common::repository::Repository;
use std::env;
use std::fs;
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bzip2 = "0.4.4"
flate2 = "1.0.30"
futures = "0.3.30"
futures-util = "0.3.30"
infer = "0.15.0"
reqwest = { version = "0.12.4", features = ["blocking", "json", "stream"], optional = true }
serde = { version = "1.0.199", features = ["derive"] }
serde_json = "1.0.116"
Expand Down
Loading

0 comments on commit db150b1

Please sign in to comment.