Skip to content

Commit

Permalink
use tempfile directly for container file copy instead of tempdir
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Detjens <[email protected]>
  • Loading branch information
detjensrobert committed Dec 27, 2024
1 parent 03a13c8 commit f2d208e
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/builder/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::sync::LazyLock;
use std::{fs, io};
use std::{io::Read, path::Path};
use tar;
use tempfile::tempdir;
use tempfile::Builder;
use tokio;

use crate::configparser::challenge::BuildObject;
Expand Down Expand Up @@ -161,21 +161,16 @@ pub async fn copy_file(container_id: &str, from: PathBuf, to: PathBuf) -> Result
};
let mut dl_stream = client.download_from_container(container_id, Some(opts));

let mut tempdir = tempdir()?;
let tarpath = tempdir
.path()
.join(format!("download_{}.tar", from_basename.to_string_lossy()));

// collect byte stream chunks into full file
let mut tarfile = File::create(&tarpath)?;
let mut temptar = Builder::new().suffix(".tar").tempfile_in(".")?;
while let Some(chunk) = dl_stream.next().await {
tarfile.write_all(&chunk?)?;
temptar.as_file_mut().write_all(&chunk?)?;
}

// unpack file retrieved to temp dir
trace!("extracting download tar to {:?}", tarpath);
trace!("extracting download tar to {:?}", temptar.path());
// need to create new File here since tar library chokes when rewinding existing `tarfile` File
let mut tar = tar::Archive::new(File::open(&tarpath)?);
let mut tar = tar::Archive::new(File::open(temptar.path())?);

// extract single file from archive to disk
// we only copied out one file, so this tar should only have one file
Expand Down

0 comments on commit f2d208e

Please sign in to comment.