From 8d50c09c0db4e9b0644263cde3f7ff990ec75259 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Mon, 19 Sep 2022 19:31:47 +0530 Subject: [PATCH] perf(cli): avoid `canonicalize_path` if config file does not exist (#15957) --- cli/args/config_file.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 0b9c51b7cf..b0a5b355b9 100644 --- a/cli/args/config_file.rs +++ b/cli/args/config_file.rs @@ -525,6 +525,20 @@ impl ConfigFile { std::env::current_dir()?.join(path_ref) }; + // perf: Check if the config file exists before canonicalizing path. + if !config_file.exists() { + return Err( + std::io::Error::new( + std::io::ErrorKind::InvalidInput, + format!( + "Could not find the config file: {}", + config_file.to_string_lossy() + ), + ) + .into(), + ); + } + let config_path = canonicalize_path(&config_file).map_err(|_| { std::io::Error::new( std::io::ErrorKind::InvalidInput,