From f711691e1118c1d2f6f0ccea6bd2e13d155230b8 Mon Sep 17 00:00:00 2001 From: Edu4rdSHL Date: Wed, 9 Jun 2021 19:48:31 -0500 Subject: [PATCH] Initial commit. Signed-off-by: Edu4rdSHL --- examples/webtail.conf | 2 +- src/main.rs | 43 +++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/examples/webtail.conf b/examples/webtail.conf index 0e44b31..540201b 100644 --- a/examples/webtail.conf +++ b/examples/webtail.conf @@ -1,2 +1,2 @@ file1.txt:8080 -file2.txt:9090 +file2.txt:8090 diff --git a/src/main.rs b/src/main.rs index ae2851a..03d69f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, u16}; +use std::{collections::HashMap, path::Path, u16}; use webtail_rs::{ structs::{File, State}, @@ -36,23 +36,30 @@ fn main() { input_files .par_iter() .map(|(file, port)| { - println!("=> Watching file {} in port {}\n", file, port); - let error = rocket::custom( - Config::build(Environment::Production) - .log_level(LoggingLevel::Off) - .port(port.to_owned()) - .unwrap(), - ) - .manage(File { - data: String::new(), - name: file.clone(), - state: State::Write, - delay: args.delay, - }) - .mount("/", routes![updates]) - .mount("/", StaticFiles::from("static")) - .launch(); - eprintln!("Launch failed! Error: {}", error); + if Path::new(&file).exists() { + println!("=> Watching file {} in port {}\n", file, port); + let error = rocket::custom( + Config::build(Environment::Production) + .log_level(LoggingLevel::Off) + .port(port.to_owned()) + .unwrap(), + ) + .manage(File { + data: String::new(), + name: file.clone(), + state: State::Write, + delay: args.delay, + }) + .mount("/", routes![updates]) + .mount("/", StaticFiles::from("static")) + .launch(); + eprintln!( + "Launch failed for file {} in port {}! Error: {}", + file, port, error + ); + } else { + eprintln!("Ignoring file {} because doesn't exists.", file) + } }) .collect::>(); }