Skip to content

Commit

Permalink
Ensure directory exists before writing tar dir
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Jun 11, 2024
1 parent 6d3024b commit c2ec349
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion inside_docker/src/bin/make_ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn make_ruby(args: Args) -> Result<(), Error> {
))
.done();

tar_dir_to_file(&compiled_dir, output_tar_file)?;
tar_dir_to_file(&compiled_dir, &output_tar_file)?;
log.done();

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion inside_docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn output_tar_path(
.join(format!("ruby-{}.tgz", version.bundler_format()))
}

pub fn tar_dir_to_file(compiled_dir: &Path, tar_file: File) -> Result<(), Error> {
pub fn tar_dir_to_file(compiled_dir: &Path, tar_file: &File) -> Result<(), Error> {
let enc = flate2::write::GzEncoder::new(tar_file, flate2::Compression::best());

let mut tar = tar::Builder::new(enc);
Expand Down
28 changes: 12 additions & 16 deletions jruby_executable/src/bin/jruby_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,23 @@ fn jruby_build(args: &Args) -> Result<(), Error> {

log = {
let mut bullet = log.bullet("Creating tgz archives");
let tar_dir = volume_output_dir
.join(base_image.to_string())
.join(&tgz_name);

let timer = bullet.start_timer(format!("Write {}", tar_dir.display()));
tar_dir_to_file(
&jruby_dir,
fs_err::File::create(&tar_dir).map_err(Error::IoError)?,
)?;
let tar_dir = volume_output_dir.join(base_image.to_string());

fs_err::create_dir_all(&tar_dir).map_err(Error::IoError)?;

let tar_file = fs_err::File::create(tar_dir.join(&tgz_name)).map_err(Error::IoError)?;

let timer = bullet.start_timer(format!("Write {}", tar_file.path().display()));
tar_dir_to_file(&jruby_dir, &tar_file)?;
bullet = timer.done();

for arch in &["amd64", "arm64"] {
let path = volume_output_dir
.join(base_image.to_string())
.join(arch)
.join(&tgz_name);

fs_err::create_dir_all(path.parent().expect("Parent dir")).map_err(Error::IoError)?;
let dir = volume_output_dir.join(base_image.to_string()).join(arch);
fs_err::create_dir_all(&dir).map_err(Error::IoError)?;

let path = dir.join(&tgz_name);
bullet = bullet.sub_bullet(format!("Write {}", path.display()));
fs_err::copy(&tar_dir, &path).map_err(Error::IoError)?;
fs_err::copy(tar_file.path(), &path).map_err(Error::IoError)?;
}

bullet.done()
Expand Down

0 comments on commit c2ec349

Please sign in to comment.