Skip to content

Commit 30daae8

Browse files
authored
Merge pull request #114 from stonemaster/main
Allow to disable ZIP compression & fix bug in overwriting info files Merging as the clippy failures are in the agent and not the composer as worked on as part of this PR.
2 parents f6b44a4 + 02f29c8 commit 30daae8

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

core-dump-composer/src/config.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct CoreConfig {
2626
pub os_hostname: String,
2727
pub filename_template: String,
2828
pub params: CoreParams,
29+
pub disable_compression: bool,
2930
}
3031

3132
#[derive(Serialize)]
@@ -59,9 +60,10 @@ impl CoreConfig {
5960
let pathname = matches.value_of("pathname").unwrap_or("").to_string();
6061
let timeout = matches
6162
.value_of("timeout")
62-
.unwrap_or("120")
63+
.unwrap_or("600")
6364
.parse::<u64>()
6465
.unwrap();
66+
let disable_compression = matches.contains_id("disable-compression");
6567

6668
let uuid = Uuid::new_v4();
6769

@@ -144,6 +146,7 @@ impl CoreConfig {
144146
filename_template,
145147
log_length,
146148
params,
149+
disable_compression,
147150
})
148151
}
149152

@@ -208,11 +211,11 @@ impl CoreConfig {
208211
format!("{}-ps-info.json", self.get_templated_name())
209212
}
210213

211-
pub fn get_image_filename(&self, counter: u32) -> String {
214+
pub fn get_image_filename(&self, counter: usize) -> String {
212215
format!("{}-{}-image-info.json", self.get_templated_name(), counter)
213216
}
214217

215-
pub fn get_log_filename(&self, counter: u32) -> String {
218+
pub fn get_log_filename(&self, counter: usize) -> String {
216219
format!("{}-{}.log", self.get_templated_name(), counter)
217220
}
218221
pub fn get_zip_full_path(&self) -> String {
@@ -315,6 +318,13 @@ pub fn try_get_matches() -> clap::Result<ArgMatches> {
315318
.takes_value(true)
316319
.help("test-threads mapped to support the test scenarios"),
317320
)
321+
.arg(
322+
Arg::new("disable-compression")
323+
.short('D')
324+
.long("disable-compression")
325+
.takes_value(false)
326+
.help("Disables deflate compression in resulting zip file and stores data uncompressed."),
327+
)
318328
.try_get_matches()
319329
}
320330

core-dump-composer/src/main.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
111111
cc.set_podname(podname.to_string());
112112

113113
// Create the base zip file that we are going to put everything into
114+
let compression_method = if cc.disable_compression {
115+
zip::CompressionMethod::Stored
116+
} else {
117+
zip::CompressionMethod::Deflated
118+
};
114119
let options = FileOptions::default()
115-
.compression_method(zip::CompressionMethod::Deflated)
120+
.compression_method(compression_method)
116121
.unix_permissions(0o444)
117122
.large_file(true);
118123

@@ -159,20 +164,14 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
159164

160165
let stdin = io::stdin();
161166
let mut stdin = stdin.lock();
162-
let mut data = [0u8; 8192];
163167

164-
while let Ok(n) = stdin.read(&mut data) {
165-
if n == 0 {
166-
break;
168+
match io::copy(&mut stdin, &mut zip) {
169+
Ok(v) => v,
170+
Err(e) => {
171+
error!("Error writing core file \n{}", e);
172+
process::exit(1);
167173
}
168-
match zip.write_all(&data) {
169-
Ok(v) => v,
170-
Err(e) => {
171-
error!("Error writing core file \n{}", e);
172-
process::exit(1);
173-
}
174-
};
175-
}
174+
};
176175
zip.flush()?;
177176

178177
if cc.ignore_crio {
@@ -306,8 +305,7 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
306305
debug!("Successfully got the process details {}", ps_object);
307306

308307
if let Some(containers) = ps_object["containers"].as_array() {
309-
for container in containers {
310-
let counter = 0;
308+
for (counter, container) in containers.iter().enumerate() {
311309
let img_ref = match container["imageRef"].as_str() {
312310
Some(v) => v,
313311
None => {

0 commit comments

Comments
 (0)