git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] help: correct behavior for is_executable on Windows

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 12, 2012, 04:30 UTC
Message-ID
<7vd32whgvl.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120811070030.GA83665@book.hvoigt.net>
Heiko Voigt <hvoigt@hvoigt.net> writes:
Show 39 quoted lines
>  help.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/help.c b/help.c
> index 662349d..b41fa21 100644
> --- a/help.c
> +++ b/help.c
> @@ -103,10 +103,19 @@ static int is_executable(const char *name)
>  		return 0;
>  
>  #if defined(WIN32) || defined(__CYGWIN__)
> +	/* On Windows we cannot use the executable bit. The executable
> +	 * state is determined by extension only. We do this first
> +	 * because with virus scanners opening an executeable for
> +	 * reading is potentially expensive.
> +	 */
> +	if (has_extension(name, ".exe"))
> +		return S_IXUSR;
> +
>  #if defined(__CYGWIN__)
>  if ((st.st_mode & S_IXUSR) == 0)
>  #endif
> -{	/* cannot trust the executable bit, peek into the file instead */
> +{	/* 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);
> @@ -114,8 +123,8 @@ if ((st.st_mode & S_IXUSR) == 0)
>  	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);
>  	}

Would it make sense to move this to compat/win32/, compat/cygwin.c, and compat/posix.c, each exporting is_executable(const char *path), so that we do not have to suffer the #ifdef mess?

Previous: Heiko VoigtNext: Heiko Voigt
Message 2 of 11 in “help: correct behavior for is_executable on Windows”
  1. help: correct behavior for is_executable on WindowsHeiko Voigt, Aug 11, 2012
  2. Junio C HamanoAug 12, 2012
  3. Heiko VoigtAug 13, 2012
  4. Junio C HamanoAug 13, 2012
  5. Heiko VoigtAug 15, 2012
  6. Junio C HamanoAug 15, 2012
  7. Junio C HamanoAug 15, 2012
  8. Heiko VoigtAug 15, 2012
  9. Junio C HamanoAug 15, 2012
  10. Junio C HamanoAug 16, 2012
  11. Heiko VoigtAug 16, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.