From f567965412e26abf7c435762eb7d0e28c78b21a0 Mon Sep 17 00:00:00 2001 From: Khanh Duong Quoc Date: Mon, 14 Oct 2024 06:54:00 +0900 Subject: [PATCH] Getting config directory by absolute path --- selene/src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/selene/src/main.rs b/selene/src/main.rs index 2a9de0e7..4e9bc3ac 100644 --- a/selene/src/main.rs +++ b/selene/src/main.rs @@ -523,10 +523,16 @@ fn start(mut options: opts::Options) { }; match toml::from_str(&config_contents) { - Ok(config) => ( - config, - Path::new(&config_file).parent().map(Path::to_path_buf), - ), + Ok(config) => { + // Get config directory to using absolute path. + // There is case where `config = Some("selene.toml")`, + // which returns `""`` when getting parent directory. + let config_directory = Path::new(&config_file) + .canonicalize() + .ok() + .and_then(|path| path.parent().map(|path| path.to_path_buf())); + (config, config_directory) + } Err(error) => { error!("Config file not in correct format: {}", error); std::process::exit(1);