git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Adam Roben via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Adam Roben <adam@roben.org>
Subject: Re: [PATCH 1/1] mingw: fix launching of externals from Unicode paths
Date: Mon, 26 Aug 2019 10:09:28 -0700	[thread overview]
Message-ID: <xmqqv9ujhn07.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <8f2d64a88518d05579701b7093ecbc197ebca2c7.1566686335.git.gitgitgadget@gmail.com> (Adam Roben via GitGitGadget's message of "Sat, 24 Aug 2019 15:38:56 -0700 (PDT)")

"Adam Roben via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Note that the only problem in this function was calling
> `GetFileAttributes()` instead of `GetFileAttributesW()`. The calls to
> `access()` were fine because `access()` is a macro which resolves to
> `mingw_access()`, which already handles Unicode correctly. But
> `lookup_prog()` was changed to use `_waccess()` directly so that we only
> convert the path to UTF-16 once.

Nicely explained.  Thanks.

>
> To make things work correctly, we have to maintain UTF-8 and UTF-16
> versions in tandem in `lookup_prog()`.
>
> Signed-off-by: Adam Roben <adam@roben.org>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  compat/mingw.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 8141f77189..9f02403ebf 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1161,14 +1161,21 @@ static char *lookup_prog(const char *dir, int dirlen, const char *cmd,
>  			 int isexe, int exe_only)
>  {
>  	char path[MAX_PATH];
> +	wchar_t wpath[MAX_PATH];
>  	snprintf(path, sizeof(path), "%.*s\\%s.exe", dirlen, dir, cmd);
>  
> -	if (!isexe && access(path, F_OK) == 0)
> +	if (xutftowcs_path(wpath, path) < 0)
> +		return NULL;
> +
> +	if (!isexe && _waccess(wpath, F_OK) == 0)
>  		return xstrdup(path);
> -	path[strlen(path)-4] = '\0';
> -	if ((!exe_only || isexe) && access(path, F_OK) == 0)
> -		if (!(GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY))
> +	wpath[wcslen(wpath)-4] = '\0';
> +	if ((!exe_only || isexe) && _waccess(wpath, F_OK) == 0) {
> +		if (!(GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY)) {
> +			path[strlen(path)-4] = '\0';
>  			return xstrdup(path);
> +		}
> +	}
>  	return NULL;
>  }

      reply	other threads:[~2019-08-26 17:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-24 22:38 [PATCH 0/1] mingw: handle non-ASCII PATH components correctly Johannes Schindelin via GitGitGadget
2019-08-24 22:38 ` [PATCH 1/1] mingw: fix launching of externals from Unicode paths Adam Roben via GitGitGadget
2019-08-26 17:09   ` Junio C Hamano [this message]

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=xmqqv9ujhn07.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=adam@roben.org \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /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).