perf(cli): avoid canonicalize_path if config file does not exist (#15957)

This commit is contained in:
Divy Srivastava 2022-09-19 19:31:47 +05:30 committed by GitHub
parent e2f3801221
commit 8d50c09c0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,