Skip to content

Commit

Permalink
feat: updater - remove external tar use
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Apr 30, 2024
1 parent 442b610 commit 3078a02
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
35 changes: 35 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ clap-markdown = { git = "https://github.com/getgrit/clap-markdown", rev = "4568d
flate2 = { version = "1.0.17", features = [
"rust_backend",
], default-features = false }
tar = "0.4.38"

opentelemetry-otlp = { version = "0.14.0", optional = true, features = [
"http-proto",
Expand Down
29 changes: 18 additions & 11 deletions crates/cli/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use std::fmt;
use std::io::Read;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::fs as async_fs;
use tokio::fs::File;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::process::Command as AsyncCommand;
use tokio::sync::Mutex;
use uuid::Uuid;

Expand Down Expand Up @@ -460,6 +460,19 @@ impl Updater {
Ok(target_path)
}

async fn uncompress_tarball(&self, packed_path: &PathBuf) -> Result<Vec<u8>> {
let mut bytes = vec![];
File::open(&packed_path)
.await?
.read_to_end(&mut bytes)
.await?;
let mut tarball_bytes = vec![];
let mut decoder = flate2::read::GzDecoder::new(bytes.as_slice());
decoder.read_to_end(&mut tarball_bytes)?;

Ok(tarball_bytes)
}

async fn unpack_artifact(&self, app: SupportedApp, packed_path: PathBuf) -> Result<()> {
let unpacked_dir = self.bin_path.join(format!("{}-bin", app.get_bin_name()));
// Create the subdir
Expand All @@ -471,16 +484,10 @@ impl Updater {
unpacked_dir.display()
);

let output = AsyncCommand::new("tar")
.arg("-xzf")
.arg(packed_path)
.arg("-C")
.arg(&unpacked_dir)
.output()
.await?;

if !output.status.success() {
bail!("Failed to unpack files: {:?}", output);
let tarball_bytes = self.uncompress_tarball(&packed_path).await?;
let mut tarball = tar::Archive::new(tarball_bytes.as_slice());
if let Err(e) = tarball.unpack(&unpacked_dir) {
bail!("Failed to unpack files: {:?}", e);
}

let target_path = self.get_app_bin(&app)?;
Expand Down

0 comments on commit 3078a02

Please sign in to comment.