diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-09-19 19:31:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-19 19:31:47 +0530 |
commit | 8d50c09c0db4e9b0644263cde3f7ff990ec75259 (patch) | |
tree | 306d90f790b4dd4c32cff040d4385169335cbc60 | |
parent | e2f38012215bb3b0f4fe67bbd40ef2ddab2a6caf (diff) |
perf(cli): avoid `canonicalize_path` if config file does not exist (#15957)
-rw-r--r-- | cli/args/config_file.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cli/args/config_file.rs b/cli/args/config_file.rs index 0b9c51b7c..b0a5b355b 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, |