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 cbd56bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use serde_json::{self};
use std::collections::HashMap;
use std::{fs, time};
use std::io::Write;
use std::path::Path;
use std::sync::Mutex;
use thiserror::Error;
Expand Down Expand Up @@ -209,6 +210,7 @@ impl PerformanceData {
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&dir_name, &self.init_params.dir_name)?;
tar.into_inner()?.flush()?;
info!("Data collected in {}/, archived in {}", self.init_params.dir_name, archive_path);
Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn form_and_copy_archive(loc: String, report_name: &PathBuf) -> Result<()> {
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&dir_stem, &loc)?;
tar.into_inner()?.flush()?;

/* Copy archive to aperf_report */
let archive_dst = report_name.join(format!("data/archive/{}", archive_name));
Expand Down Expand Up @@ -227,6 +228,7 @@ pub fn report(report: &Report) -> Result<()> {
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.append_dir_all(&report_name, &report_name)?;
tar.into_inner()?.flush()?;
fs::remove_dir_all(APERF_TMP)?;
Ok(())
}

0 comments on commit cbd56bb

Please sign in to comment.