mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-12-22 16:35:51 -05:00
feat: verify config file exists and can be read
This commit is contained in:
parent
34f497a650
commit
edf7af1573
28
src/main.rs
28
src/main.rs
|
@ -7,6 +7,9 @@ use nostr_rs_relay::server::start_server;
|
|||
use std::sync::mpsc as syncmpsc;
|
||||
use std::sync::mpsc::{Receiver as MpscReceiver, Sender as MpscSender};
|
||||
use std::thread;
|
||||
use std::path::Path;
|
||||
use std::fs;
|
||||
use std::process;
|
||||
#[cfg(not(target_env = "msvc"))]
|
||||
use tikv_jemallocator::Jemalloc;
|
||||
use tracing::info;
|
||||
|
@ -24,6 +27,31 @@ fn main() {
|
|||
// get config file name from args
|
||||
let config_file_arg = args.config;
|
||||
|
||||
// Quits if config file path is unreadable or does not exist
|
||||
let config_file_path = config_file_arg.as_ref().map(|x| &**x).unwrap();
|
||||
let path = Path::new(&config_file_path);
|
||||
|
||||
if !path.exists() {
|
||||
eprintln!("Config file not found: {}", &config_file_path);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
if !path.is_file() {
|
||||
eprintln!("Invalid config file path: {}", &config_file_path);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
if let Err(err) = fs::metadata(&path) {
|
||||
eprintln!("Error while accessing file metadata: {}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
if let Err(err) = fs::File::open(&path) {
|
||||
eprintln!("Config file is not readable: {}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
let mut _log_guard: Option<WorkerGuard> = None;
|
||||
|
||||
// configure settings from the config file (defaults to config.toml)
|
||||
|
|
Loading…
Reference in New Issue
Block a user