mirror of
https://github.com/git/git.git
synced 2026-01-28 11:32:24 +00:00
Merge 'fix-is-exe' into HEAD
This commit is contained in:
21
help.c
21
help.c
@@ -105,7 +105,22 @@ static int is_executable(const char *name)
|
||||
return 0;
|
||||
|
||||
#if defined(GIT_WINDOWS_NATIVE)
|
||||
{ /* cannot trust the executable bit, peek into the file instead */
|
||||
/*
|
||||
* On Windows there is no executable bit. The file extension
|
||||
* indicates whether it can be run as an executable, and Git
|
||||
* has special-handling to detect scripts and launch them
|
||||
* through the indicated script interpreter. We test for the
|
||||
* file extension first because virus scanners may make
|
||||
* opening an executable for reading expensive.
|
||||
*/
|
||||
if (ends_with(name, ".exe"))
|
||||
return S_IXUSR;
|
||||
|
||||
{
|
||||
/*
|
||||
* Now that we know it does not have an executable extension,
|
||||
* peek into the file instead.
|
||||
*/
|
||||
char buf[3] = { 0 };
|
||||
int n;
|
||||
int fd = open(name, O_RDONLY);
|
||||
@@ -113,8 +128,8 @@ static int is_executable(const char *name)
|
||||
if (fd >= 0) {
|
||||
n = read(fd, buf, 2);
|
||||
if (n == 2)
|
||||
/* DOS executables start with "MZ" */
|
||||
if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
|
||||
/* look for a she-bang */
|
||||
if (!strcmp(buf, "#!"))
|
||||
st.st_mode |= S_IXUSR;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user