Skip to content

Commit 7367db6

Browse files
committed
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
1 parent 3f44083 commit 7367db6

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/tools/tidy/src/bins.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,27 @@ pub fn check(path: &Path, bad: &mut bool) {
4444
let filename = file.file_name().unwrap().to_string_lossy();
4545
let extensions = [".py", ".sh"];
4646
if extensions.iter().any(|e| filename.ends_with(e)) {
47-
return
47+
return;
4848
}
4949

5050
let metadata = t!(fs::symlink_metadata(&file), &file);
5151
if metadata.mode() & 0o111 != 0 {
5252
let rel_path = file.strip_prefix(path).unwrap();
5353
let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
54-
let ret_code = Command::new("git")
55-
.arg("ls-files")
56-
.arg(&git_friendly_path)
57-
.current_dir(path)
58-
.stdout(Stdio::null())
59-
.stderr(Stdio::null())
60-
.status()
61-
.unwrap_or_else(|e| {
62-
panic!("could not run git ls-files: {}", e);
63-
});
64-
if ret_code.success() {
54+
let output = Command::new("git")
55+
.arg("ls-files")
56+
.arg(&git_friendly_path)
57+
.current_dir(path)
58+
.stderr(Stdio::null())
59+
.output()
60+
.unwrap_or_else(|e| {
61+
panic!("could not run git ls-files: {}", e);
62+
});
63+
let path_bytes = rel_path.as_os_str().as_bytes();
64+
if output.status.success() && output.stdout.starts_with(path_bytes) {
6565
println!("binary checked into source: {}", file.display());
6666
*bad = true;
6767
}
6868
}
6969
})
7070
}
71-

0 commit comments

Comments
 (0)