Skip to content

Commit

Permalink
use temporary file for pack command
Browse files Browse the repository at this point in the history
  • Loading branch information
sokorototo committed Jun 11, 2024
1 parent 57d82f6 commit 5b32ede
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
27 changes: 23 additions & 4 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 vach-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 4 additions & 5 deletions vach-cli/src/commands/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 5b32ede

Please sign in to comment.