Skip to content

Commit 4c5d32f

Browse files
committed
Merge 'fix-is-exe' into HEAD
2 parents b8ed9d4 + d763739 commit 4c5d32f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

help.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,25 @@ static int is_executable(const char *name)
107107
return 0;
108108

109109
#if defined(GIT_WINDOWS_NATIVE)
110-
{ /* cannot trust the executable bit, peek into the file instead */
110+
/* On Windows we cannot use the executable bit. The executable
111+
* state is determined by extension only. We do this first
112+
* because with virus scanners opening an executeable for
113+
* reading is potentially expensive.
114+
*/
115+
if (ends_with(name, ".exe"))
116+
return S_IXUSR;
117+
118+
{ /* now that we know it does not have an executable extension,
119+
peek into the file instead */
111120
char buf[3] = { 0 };
112121
int n;
113122
int fd = open(name, O_RDONLY);
114123
st.st_mode &= ~S_IXUSR;
115124
if (fd >= 0) {
116125
n = read(fd, buf, 2);
117126
if (n == 2)
118-
/* DOS executables start with "MZ" */
119-
if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
127+
/* look for a she-bang */
128+
if (!strcmp(buf, "#!"))
120129
st.st_mode |= S_IXUSR;
121130
close(fd);
122131
}

0 commit comments

Comments
 (0)