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.
This commit is contained in:
Kamal Marhubi 2016-01-31 01:48:14 -05:00
parent fb17a44584
commit bd9ad6b0a0

View file

@ -57,9 +57,12 @@ fn lookup_project_file(input_file: &Path) -> io::Result<PathBuf> {
loop { loop {
let config_file = current.join("rustfmt.toml"); let config_file = current.join("rustfmt.toml");
if fs::metadata(&config_file).is_ok() { 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); return Ok(config_file);
} }
}
// If the current directory has no parent, we're done searching. // If the current directory has no parent, we're done searching.
if !current.pop() { if !current.pop() {