Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6195099

Browse files
committed
Merge 'fix-is-exe' into HEAD
2 parents ca1a6ed + 872abf4 commit 6195099

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

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

0 commit comments

Comments
 (0)