From 4fd71311a191fd283c5bcc8a4344f9e62510075b Mon Sep 17 00:00:00 2001 From: Kenneth Gitere Date: Fri, 30 Apr 2021 07:47:25 +0300 Subject: [PATCH] Fix bug when validating the download file name in merged mode --- src/cli.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index f1f38bc..19ce379 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -101,16 +101,24 @@ pub fn cli_init() -> AppConfig { if let Some(name) = arg_matches.value_of("output_name") { let file_path = Path::new(name); - if !file_path.is_file() { - eprintln!("{:?} is not a vaild file", name); + if file_path.is_dir() { + eprintln!("{:?} is a directory", name); std::process::exit(1); } - let file_name = if name.ends_with(".epub") && name.len() > 5 { + let file_name = if file_path.extension().is_some() { name.to_owned() } else { name.to_owned() + ".epub" }; + + match std::fs::File::create(&file_name) { + Ok(_) => (), + Err(e) => { + eprintln!("Unable to create file {:?}\n{}", file_path, e); + std::process::exit(1) + } + } app_config.merged = Some(file_name); }