Skip to content

Commit

Permalink
Flush buffer after forming archive
Browse files Browse the repository at this point in the history
Data remains in the GzEncoder. Ensure it is flushed before performing
any other operations on the tarball.

This fixes a bug in the report generation, where the tarball of the raw
data is copied to data/archive/. When trying to untar the file, the data
is corrupted and unuseable.
  • Loading branch information
janaknat committed Aug 14, 2023
1 parent 3587733 commit cc149f6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ pub fn form_and_copy_archive(loc: String, report_name: &PathBuf) -> Result<()> {
/* Create a temp archive */
let archive_name = format!("{}.tar.gz", &dir_stem);
let archive_path = format!("{}/{}", APERF_TMP, archive_name);
let tar_gz = fs::File::create(&archive_path)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&dir_stem, &loc)?;
let archive_dst = report_name.join(format!("data/archive/{}", archive_name));
{
let tar_gz = fs::File::create(&archive_path)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&dir_stem, &loc)?;
}

/* Copy archive to aperf_report */
let archive_dst = report_name.join(format!("data/archive/{}", archive_name));
fs::copy(&archive_path, archive_dst)?;
return Ok(());
}
Expand Down

0 comments on commit cc149f6

Please sign in to comment.