Fix using temp file for archive (#6058)

* Fix using temp file for archive

* Rename the temp archive instead of hardlinking it
This commit is contained in:
Sagar Dhawan
2019-09-24 15:24:54 -07:00
committed by GitHub
parent 5763d63737
commit 374b776a3e

View File

@ -109,14 +109,10 @@ impl SnapshotPackagerService {
symlink::symlink_dir(storage_path, output_path)?; symlink::symlink_dir(storage_path, output_path)?;
} }
// Tar the staging directory into the archive `temp_tar_gz` // Tar the staging directory into the archive at `archive_path`
let temp_tar_gz = tempfile::Builder::new() let archive_path = tar_dir.join("new_state.tar.bz2");
.prefix("new_state")
.suffix(".tar.bz2")
.tempfile_in(tar_dir)?;
let temp_tar_path = temp_tar_gz.path();
let mut args = vec!["jcfhS"]; let mut args = vec!["jcfhS"];
args.push(temp_tar_path.to_str().unwrap()); args.push(archive_path.to_str().unwrap());
args.push("-C"); args.push("-C");
args.push(staging_dir.path().to_str().unwrap()); args.push(staging_dir.path().to_str().unwrap());
args.push(TAR_ACCOUNTS_DIR); args.push(TAR_ACCOUNTS_DIR);
@ -138,8 +134,8 @@ impl SnapshotPackagerService {
// Once everything is successful, overwrite the previous tarball so that other validators // Once everything is successful, overwrite the previous tarball so that other validators
// can fetch this newly packaged snapshot // can fetch this newly packaged snapshot
let _ = fs::remove_file(&snapshot_package.tar_output_file); let _ = fs::remove_file(&snapshot_package.tar_output_file);
let metadata = fs::metadata(&temp_tar_path)?; let metadata = fs::metadata(&archive_path)?;
fs::hard_link(&temp_tar_path, &snapshot_package.tar_output_file)?; fs::rename(&archive_path, &snapshot_package.tar_output_file)?;
timer.stop(); timer.stop();
info!( info!(