diff --git a/core-dump-composer/src/config.rs b/core-dump-composer/src/config.rs index 5711600..f555ecb 100644 --- a/core-dump-composer/src/config.rs +++ b/core-dump-composer/src/config.rs @@ -26,6 +26,7 @@ pub struct CoreConfig { pub os_hostname: String, pub filename_template: String, pub params: CoreParams, + pub disable_compression: bool, } #[derive(Serialize)] @@ -59,9 +60,10 @@ impl CoreConfig { let pathname = matches.value_of("pathname").unwrap_or("").to_string(); let timeout = matches .value_of("timeout") - .unwrap_or("120") + .unwrap_or("600") .parse::() .unwrap(); + let disable_compression = matches.contains_id("disable-compression"); let uuid = Uuid::new_v4(); @@ -144,6 +146,7 @@ impl CoreConfig { filename_template, log_length, params, + disable_compression, }) } @@ -208,11 +211,11 @@ impl CoreConfig { format!("{}-ps-info.json", self.get_templated_name()) } - pub fn get_image_filename(&self, counter: u32) -> String { + pub fn get_image_filename(&self, counter: usize) -> String { format!("{}-{}-image-info.json", self.get_templated_name(), counter) } - pub fn get_log_filename(&self, counter: u32) -> String { + pub fn get_log_filename(&self, counter: usize) -> String { format!("{}-{}.log", self.get_templated_name(), counter) } pub fn get_zip_full_path(&self) -> String { @@ -315,6 +318,13 @@ pub fn try_get_matches() -> clap::Result { .takes_value(true) .help("test-threads mapped to support the test scenarios"), ) + .arg( + Arg::new("disable-compression") + .short('D') + .long("disable-compression") + .takes_value(false) + .help("Disables deflate compression in resulting zip file and stores data uncompressed."), + ) .try_get_matches() } diff --git a/core-dump-composer/src/main.rs b/core-dump-composer/src/main.rs index bb5e8a9..74d1f3a 100644 --- a/core-dump-composer/src/main.rs +++ b/core-dump-composer/src/main.rs @@ -111,8 +111,13 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> { cc.set_podname(podname.to_string()); // Create the base zip file that we are going to put everything into + let compression_method = if cc.disable_compression { + zip::CompressionMethod::Stored + } else { + zip::CompressionMethod::Deflated + }; let options = FileOptions::default() - .compression_method(zip::CompressionMethod::Deflated) + .compression_method(compression_method) .unix_permissions(0o444) .large_file(true); @@ -159,20 +164,14 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> { let stdin = io::stdin(); let mut stdin = stdin.lock(); - let mut data = [0u8; 8192]; - while let Ok(n) = stdin.read(&mut data) { - if n == 0 { - break; + match io::copy(&mut stdin, &mut zip) { + Ok(v) => v, + Err(e) => { + error!("Error writing core file \n{}", e); + process::exit(1); } - match zip.write_all(&data) { - Ok(v) => v, - Err(e) => { - error!("Error writing core file \n{}", e); - process::exit(1); - } - }; - } + }; zip.flush()?; if cc.ignore_crio { @@ -306,8 +305,7 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> { debug!("Successfully got the process details {}", ps_object); if let Some(containers) = ps_object["containers"].as_array() { - for container in containers { - let counter = 0; + for (counter, container) in containers.iter().enumerate() { let img_ref = match container["imageRef"].as_str() { Some(v) => v, None => {