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 13, 2012, 17:48 UTC
Message-ID
<7vmx1yel9d.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120813170221.GB6418@book.hvoigt.net>
Heiko Voigt <hvoigt@hvoigt.net> writes:
Show 23 quoted lines
> Since the code for cygwin and windows in general is almost the same I would
> extract one function for them where I leave in one ifdef for cygwin.
>
> E.g. like this:
>
>
> 	static int is_executable(const char *name)
> 	{
> 	        struct stat st;
>
> 	        if (stat(name, &st) || /* stat, not lstat */
> 	            !S_ISREG(st.st_mode))
> 	                return 0;
>
> 		fill_platform_stat(name, &st);
>
> 	        return st.st_mode & S_IXUSR;
> 	}
>
> which I could then define to a no op on posix. That way we avoid code
> duplication in the platform specific functions.
>
> What do you think?

Does having the "stat()" help on Windows in any way? Does it ever return an executable bit by itself?

If not, Windows compat/ implementation may want to skip issuing a useless stat() and write it as

	if (has_extension(".exe"))
        	return 1;
	if (contents_begins_with("MZ") || contents_begins_with("#!"))
        	return 1;
	return 0;

without ever talking about stat() which is POSIXism compat/ implementation for Windows does not have to worry about.

And that was the reason I suggested making the whole implementation of path_is_executable() overridable by compat/ layer.

But if having "stat()" helps on Windows, then your counterproposal is good enough for me.

Thanks.
Previous: Heiko VoigtNext: Heiko Voigt
Message 4 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.