Skip to content

Commit

Permalink
cli: Don't create an empty FileListGC/PC.scr when the optional parame…
Browse files Browse the repository at this point in the history
…ter is not asking for one, the heck is that .then_some() doing when it shouldn't run on false? Avoid creating that file if it already exists there, don't overwrite it by mistake.
  • Loading branch information
Swyter committed Aug 19, 2023
1 parent 57e5d29 commit 1ef8644
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions eurochef/cli/src/filelist/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,26 @@ pub fn execute_command(
};

if let Some(p) = platform {
println!("Detected platform {:?}", p);
println!("Detected platform: {:?}", p);
}

let mut scr_file = create_scr.then_some(
File::create(Path::new(&output_folder).join(format!(
"FileList{}.scr",
platform.map(|p| p.shorthand().to_uppercase()).unwrap_or(String::new())
)))
.context("Failed to create .scr file")?,
);
let mut scr_file: Option<File> = None;
let scr_path = Path::new(&output_folder).join(format!(
"FileList{}.scr",
platform.map(|p| p.shorthand().to_uppercase()).unwrap_or(String::new())
));

// swy: why does then_some() run when create_scr is false? another of life's mysteries
if create_scr != false {
if scr_path.is_file() {
println!("The file at «{}» already exists, move or rename it; we don't want to overwrite it", scr_path.display());
} else {
scr_file = create_scr.then_some(
File::create(scr_path.clone()).context("Failed to create .scr file")?,
);
println!("Creating an {} file", scr_path.file_name().and_then(|s| s.to_str()).unwrap()); // swy: what the heck is this garbage syntax?!
}
}

scr_file.as_mut().map(|f| {
writeln!(
Expand Down

0 comments on commit 1ef8644

Please sign in to comment.