Create genesis.tar.bz2 in solana-genesis (#7039)

* Use clap_utils

* Create genesis.tar.bz2 in solana-genesis

* Remove shell-based genesis.tar.bz2 generation

* Make Option=>Result conv more rusty

* stop using solana_logger

* Simplify by just using vec!

* clean up abit
This commit is contained in:
Ryo Onodera
2019-11-22 02:57:27 +09:00
committed by Michael Vines
parent 79199711b8
commit 8cbc450192
5 changed files with 57 additions and 36 deletions

View File

@ -1856,6 +1856,36 @@ pub fn create_new_ledger(ledger_path: &Path, genesis_config: &GenesisConfig) ->
blocktree.insert_shreds(shreds, None, false)?;
blocktree.set_roots(&[0])?;
// Explicitly close the blocktree before we create the archived genesis file
drop(blocktree);
let archive_path = ledger_path.join("genesis.tar.bz2");
let args = vec![
"jcfhS",
archive_path.to_str().unwrap(),
"-C",
ledger_path.to_str().unwrap(),
"genesis.bin",
"rocksdb",
];
let output = std::process::Command::new("tar")
.args(&args)
.output()
.unwrap();
if !output.status.success() {
use std::io::{Error as IOError, ErrorKind};
use std::str::from_utf8;
eprintln!("tar stdout: {}", from_utf8(&output.stdout).unwrap_or("?"));
eprintln!("tar stderr: {}", from_utf8(&output.stderr).unwrap_or("?"));
return Err(BlocktreeError::IO(IOError::new(
ErrorKind::Other,
format!(
"Error trying to generate snapshot archive: {}",
output.status
),
)));
}
Ok(last_hash)
}