Skip to content

Commit cb92d1b

Browse files
committed
Merge 'fix-is-exe' into HEAD
2 parents 5fe063c + 1f3fb3f commit cb92d1b

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
@@ -105,16 +105,25 @@ static int is_executable(const char *name)
105105
return 0;
106106

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

0 commit comments

Comments
 (0)