diff --git a/Cargo.lock b/Cargo.lock index a6f93468..0e61a6b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,6 +463,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + [[package]] name = "fiat-crypto" version = "0.2.5" @@ -623,9 +629,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "linux-raw-sys" @@ -914,9 +920,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.4.1", "errno", @@ -1077,6 +1083,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "term_size" version = "0.3.2" @@ -1216,6 +1234,7 @@ dependencies = [ "indicatif", "num_cpus", "tabled", + "tempfile", "term_size", "vach 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir", diff --git a/vach-cli/Cargo.toml b/vach-cli/Cargo.toml index 61d651d6..a2b50ac4 100644 --- a/vach-cli/Cargo.toml +++ b/vach-cli/Cargo.toml @@ -27,3 +27,4 @@ anyhow = "1.0.81" tabled = "0.15.0" walkdir = "2.5.0" term_size = "0.3.2" +tempfile = "3.10.1" diff --git a/vach-cli/src/commands/pack.rs b/vach-cli/src/commands/pack.rs index 1c77780c..2ffc06ce 100644 --- a/vach-cli/src/commands/pack.rs +++ b/vach-cli/src/commands/pack.rs @@ -6,6 +6,7 @@ use std::{ use std::path::PathBuf; use std::collections::HashSet; +use tempfile::NamedTempFile; use vach::prelude::*; use vach::crypto_utils; use indicatif::{ProgressBar, ProgressStyle}; @@ -234,10 +235,7 @@ impl CommandTrait for Evaluator { None => anyhow::bail!("Please provide an output path using the -o or --output key"), }; - let output_file = match OpenOptions::new().write(true).create_new(true).open(output_path) { - Ok(file) => file, - Err(err) => anyhow::bail!("Unable to generate archive @ {}: [IO::Error] {}", output_path, err), - }; + let mut temporary_file = NamedTempFile::new().unwrap(); // Process the files for wrapper in &mut inputs { @@ -254,8 +252,9 @@ impl CommandTrait for Evaluator { // Inform of success in input queue progress.inc(2); + let bytes_written = builder.dump(&mut temporary_file, &builder_config)?; + temporary_file.persist(output_path)?; - let bytes_written = builder.dump(output_file, &builder_config)?; progress.println(format!( "Generated a new archive @ {}; Bytes written: {}", output_path, bytes_written