From: Junio C Hamano <gitster@pobox.com>
To: Heiko Voigt <hvoigt@hvoigt.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] help: correct behavior for is_executable on Windows
Date: Sat, 11 Aug 2012 21:30:06 -0700 [thread overview]
Message-ID: <7vd32whgvl.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20120811070030.GA83665@book.hvoigt.net> (Heiko Voigt's message of "Sat, 11 Aug 2012 09:00:30 +0200")
Heiko Voigt <hvoigt@hvoigt.net> writes:
> 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?
next prev parent reply other threads:[~2012-08-12 4:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-11 7:00 [PATCH] help: correct behavior for is_executable on Windows Heiko Voigt
2012-08-12 4:30 ` Junio C Hamano [this message]
2012-08-13 17:02 ` Heiko Voigt
2012-08-13 17:48 ` Junio C Hamano
2012-08-15 16:50 ` Heiko Voigt
2012-08-15 17:53 ` Junio C Hamano
2012-08-15 19:39 ` Junio C Hamano
2012-08-15 22:29 ` Heiko Voigt
2012-08-15 23:15 ` Junio C Hamano
2012-08-16 2:02 ` Junio C Hamano
2012-08-16 16:35 ` Heiko Voigt
-- strict thread matches above, loose matches on Subject: below --
2017-01-27 13:50 Johannes Schindelin
2017-01-27 18:43 ` Junio C Hamano
2017-01-30 12:44 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vd32whgvl.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=hvoigt@hvoigt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).