]> git.lizzy.rs Git - rust.git/commitdiff
bin: Properly handle a directories named rustfmt.toml
authorKamal Marhubi <kamal@marhubi.com>
Sun, 31 Jan 2016 06:48:14 +0000 (01:48 -0500)
committerKamal Marhubi <kamal@marhubi.com>
Sun, 31 Jan 2016 06:49:29 +0000 (01:49 -0500)
`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

index a8a19d96bc775af9028d1057355b0a917f2ce703..3e31c4b5f2311e2fd3e05d400f71a70538d1fa86 100644 (file)
@@ -57,8 +57,11 @@ fn lookup_project_file(input_file: &Path) -> io::Result<PathBuf> {
 
     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.