about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@gmail.com>2016-10-15 16:17:23 -0400
committerTamir Duberstein <tamird@gmail.com>2016-10-27 21:35:57 -0400
commit7367db6fcc63c0de15b1aa58ee71d33aa3d0258b (patch)
tree23832201e1f0fbed9d41258e8376af9f8762a65e
parent3f4408347d2109803edbf53c89c8bce575de4b67 (diff)
downloadrust-7367db6fcc63c0de15b1aa58ee71d33aa3d0258b.tar.gz
rust-7367db6fcc63c0de15b1aa58ee71d33aa3d0258b.zip
tidy/bins: fix false positive on non checked-in binary
`git ls-files` now exits zero when called with a missing file; check
that the file is included in the output before reporting a checked-in
binary. Observed with git 2.10.1 and tripped by a symlink created by
tests:

src/test/run-make/issue-26006/out/time/deps/liblibc.rlib -> out/libc/liblibc.rlib
-rw-r--r--src/tools/tidy/src/bins.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/tools/tidy/src/bins.rs b/src/tools/tidy/src/bins.rs
index ea274266f1a..ef93b0858b0 100644
--- a/src/tools/tidy/src/bins.rs
+++ b/src/tools/tidy/src/bins.rs
@@ -44,28 +44,27 @@ pub fn check(path: &Path, bad: &mut bool) {
         let filename = file.file_name().unwrap().to_string_lossy();
         let extensions = [".py", ".sh"];
         if extensions.iter().any(|e| filename.ends_with(e)) {
-            return
+            return;
         }
 
         let metadata = t!(fs::symlink_metadata(&file), &file);
         if metadata.mode() & 0o111 != 0 {
             let rel_path = file.strip_prefix(path).unwrap();
             let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
-            let ret_code = Command::new("git")
-                                        .arg("ls-files")
-                                        .arg(&git_friendly_path)
-                                        .current_dir(path)
-                                        .stdout(Stdio::null())
-                                        .stderr(Stdio::null())
-                                        .status()
-                                        .unwrap_or_else(|e| {
-                                            panic!("could not run git ls-files: {}", e);
-                                        });
-            if ret_code.success() {
+            let output = Command::new("git")
+                .arg("ls-files")
+                .arg(&git_friendly_path)
+                .current_dir(path)
+                .stderr(Stdio::null())
+                .output()
+                .unwrap_or_else(|e| {
+                    panic!("could not run git ls-files: {}", e);
+                });
+            let path_bytes = rel_path.as_os_str().as_bytes();
+            if output.status.success() && output.stdout.starts_with(path_bytes) {
                 println!("binary checked into source: {}", file.display());
                 *bad = true;
             }
         }
     })
 }
-