From bd9ad6b0a0f8cf691c469846b9ee4a30be339a52 Mon Sep 17 00:00:00 2001 From: Kamal Marhubi Date: Sun, 31 Jan 2016 01:48:14 -0500 Subject: [PATCH] bin: Properly handle a directories named rustfmt.toml `lookup_project_file` could erroneously find a *directory* named `rustmfmt.toml` if there was one in its lookup path, and so ignore any configuration file it should have found further up. The error handling resulted in this silently using the default configuration. --- src/bin/rustfmt.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index a8a19d96bc7..3e31c4b5f23 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -57,8 +57,11 @@ fn lookup_project_file(input_file: &Path) -> io::Result { loop { let config_file = current.join("rustfmt.toml"); - if fs::metadata(&config_file).is_ok() { - return Ok(config_file); + if let Ok(md) = fs::metadata(&config_file) { + // Properly handle unlikely situation of a directory named `rustfmt.toml`. + if md.is_file() { + return Ok(config_file); + } } // If the current directory has no parent, we're done searching.