From 4b2ecb367d57550659510c71f19b6068cfc51ed8 Mon Sep 17 00:00:00 2001 From: veradec Date: Sun, 23 Aug 2026 22:02:06 +0530 Subject: [PATCH] add: file extension validation --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index da8e955..24a1317 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,13 @@ fn main() -> std::io::Result<()>{ .expect("Failed to init the logger"); let args: Vec = env::args().collect(); - info!("File: {}", &args[1]); + let file_path = &args[1]; + let extension = &file_path[file_path.len()-2..file_path.len()]; + if extension != "sr" { + error!("File is not in .sr"); + std::process::exit(-1); + } + info!("File: {}", file_path); let file = File::open(&args[1])?; let reader = BufReader::new(file);