Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
build: add context to unpacking git-platinum
Browse files Browse the repository at this point in the history
Signed-off-by: Fintan Halpenny <[email protected]>
  • Loading branch information
FintanH committed Jan 21, 2022
1 parent 28701f9 commit 027c00f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions surf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ criterion = "0.3"
serde_json = "1"

[build-dependencies]
anyhow = "1.0"
flate2 = "1"
tar = "0.4"

Expand Down
13 changes: 9 additions & 4 deletions surf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::Context as _;
use flate2::read::GzDecoder;
use tar::Archive;

Expand Down Expand Up @@ -62,15 +63,19 @@ fn main() {
println!("cargo:rerun-if-changed={}", git_platinum_tarball);
}

fn unpack(archive_path: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<(), std::io::Error> {
fn unpack(archive_path: impl AsRef<Path>, target: impl AsRef<Path>) -> anyhow::Result<()> {
let content = target.as_ref().join("git-platinum");
if content.exists() {
fs::remove_dir_all(content)?;
fs::remove_dir_all(content).context("attempting to remove git-platinum")?;
}
let tar_gz = File::open(archive_path.as_ref())?;
let archive_path = archive_path.as_ref();
let tar_gz = File::open(archive_path).context(format!(
"attempting to open file: {}",
archive_path.display()
))?;
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack(target)?;
archive.unpack(target).context("attempting to unpack")?;

Ok(())
}

0 comments on commit 027c00f

Please sign in to comment.