git icon indicating copy to clipboard operation
git copied to clipboard

win32: explicitly set errno to enoent if err is not error_directory

Open AZero13 opened this issue 3 years ago • 15 comments

At this point, the only two possible errors are ERROR_DIRECTORY or ERROR_BAD_PATHNAME.

This code clarifies this and also saves a call to err_win_to_posix.

Signed-off-by: Seija Kijin [email protected] cc: Ævar Arnfjörð Bjarmason [email protected] cc: Johannes Sixt [email protected]

AZero13 avatar Dec 19 '22 15:12 AZero13

Invalid author email in f71ee388061047740a4e1078b06ecb3bd2468657: "[email protected]"

gitgitgadget-git[bot] avatar Dec 19 '22 15:12 gitgitgadget-git[bot]

/submit

AZero13 avatar Dec 19 '22 15:12 AZero13

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-1402/AtariDreams/opendir-v1

To fetch this version to local tag pr-git-1402/AtariDreams/opendir-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-1402/AtariDreams/opendir-v1

gitgitgadget-git[bot] avatar Dec 19 '22 15:12 gitgitgadget-git[bot]

/submit

AZero13 avatar Dec 19 '22 15:12 AZero13

There are issues in commit 55c48908b98346ce807e09f6e1d385b781e0f26f: Win32: Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY Prefixed commit message must be in lower case

gitgitgadget-git[bot] avatar Dec 19 '22 15:12 gitgitgadget-git[bot]

There are issues in commit 55c48908b98346ce807e09f6e1d385b781e0f26f: Win32: Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY Prefixed commit message must be in lower case

gitgitgadget-git[bot] avatar Dec 19 '22 15:12 gitgitgadget-git[bot]

/submit

AZero13 avatar Dec 19 '22 16:12 AZero13

There are issues in commit 648dd85a6755af206a0a9e0abf6ecef78331ce03: win32: Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY Prefixed commit message must be in lower case

gitgitgadget-git[bot] avatar Dec 19 '22 16:12 gitgitgadget-git[bot]

There are issues in commit 648dd85a6755af206a0a9e0abf6ecef78331ce03: win32: Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY Prefixed commit message must be in lower case

gitgitgadget-git[bot] avatar Dec 19 '22 16:12 gitgitgadget-git[bot]

/submit

AZero13 avatar Dec 19 '22 16:12 AZero13

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-1402/AtariDreams/opendir-v2

To fetch this version to local tag pr-git-1402/AtariDreams/opendir-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-1402/AtariDreams/opendir-v2

gitgitgadget-git[bot] avatar Dec 19 '22 16:12 gitgitgadget-git[bot]

On the Git mailing list, Ævar Arnfjörð Bjarmason wrote (reply to this):


On Mon, Dec 19 2022, Rose via GitGitGadget wrote:

> From: Seija Kijin <[email protected]>
>
> At this point, the only two possible errors are
> ERROR_DIRECTORY or ERROR_BAD_PATHNAME.
>
> This code clarifies this and also saves a call to
> err_win_to_posix.
>
> Signed-off-by: Seija Kijin <[email protected]>
> ---
>     Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY
>     
>     At this point, the only two possible errors are ERROR_DIRECTORY or
>     ERROR_BAD_PATHNAME.
>     
>     This code clarifies this and also saves a call to err_win_to_posix.
>     
>     Signed-off-by: Seija Kijin [email protected]
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1402%2FAtariDreams%2Fopendir-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1402/AtariDreams/opendir-v1
> Pull-Request: https://github.com/git/git/pull/1402
>
>  compat/win32/dirent.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c
> index 52420ec7d4d..8f94a5ab6db 100644
> --- a/compat/win32/dirent.c
> +++ b/compat/win32/dirent.c
> @@ -34,13 +34,13 @@ DIR *opendir(const char *name)
>  	if (len && !is_dir_sep(pattern[len - 1]))
>  		pattern[len++] = '/';
>  	pattern[len++] = '*';
> -	pattern[len] = 0;
> +	pattern[len] = '\0';

Maybe the subject of this patch is a good change (I have no idea, and
don't use Windows), but this just seems like unrelated general cleanup.

I think it's probably good to change these sorts cases from 0 to '\0',
but let's do that as a seperate change...

gitgitgadget-git[bot] avatar Dec 19 '22 18:12 gitgitgadget-git[bot]

User Ævar Arnfjörð Bjarmason <[email protected]> has been added to the cc: list.

gitgitgadget-git[bot] avatar Dec 19 '22 18:12 gitgitgadget-git[bot]

On the Git mailing list, Johannes Sixt wrote (reply to this):

Am 19.12.22 um 17:20 schrieb Rose via GitGitGadget:
> From: Seija Kijin <[email protected]>
> 
> At this point, the only two possible errors are
> ERROR_DIRECTORY or ERROR_BAD_PATHNAME.
> 
> This code clarifies this and also saves a call to
> err_win_to_posix.
> 
> Signed-off-by: Seija Kijin <[email protected]>
> ---

> diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c
> index 52420ec7d4d..8f94a5ab6db 100644
> --- a/compat/win32/dirent.c
> +++ b/compat/win32/dirent.c
> @@ -34,13 +34,13 @@ DIR *opendir(const char *name)
>  	if (len && !is_dir_sep(pattern[len - 1]))
>  		pattern[len++] = '/';
>  	pattern[len++] = '*';
> -	pattern[len] = 0;
> +	pattern[len] = '\0';
>  
>  	/* open find handle */
>  	h = FindFirstFileW(pattern, &fdata);
>  	if (h == INVALID_HANDLE_VALUE) {
>  		DWORD err = GetLastError();
> -		errno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);
> +		errno = (err == ERROR_DIRECTORY) ? ENOTDIR : ENOENT;

This change does not look correct. The documentation of
FindFirstFileW()[*] does not give any guarantees that ERROR_DIRECTORY
and ERROR_BAD_PATHNAME are the only possible error values. It is
certainly not unthinkable that a hardware error is reported as
ERROR_IO_DEVICE and should be translated to EIO.

[*]
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilew

-- Hannes

gitgitgadget-git[bot] avatar Dec 20 '22 07:12 gitgitgadget-git[bot]

User Johannes Sixt <[email protected]> has been added to the cc: list.

gitgitgadget-git[bot] avatar Dec 20 '22 07:12 gitgitgadget-git[bot]