{"thread":{"id":"58980","subject":"[PATCH] Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY","startedAt":"2022-12-19T15:53:55Z","lastAt":"2022-12-20T07:22:10Z","messageCount":4,"participants":["Rose via GitGitGadget","Ævar Arnfjörð Bjarmason","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"469298","messageId":"pull.1402.git.git.1671465108414.gitgitgadget@gmail.com","threadId":"58980","inReplyTo":null,"subject":"[PATCH] Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-19T15:51:48Z","receivedAt":"2022-12-19T15:53:55Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nAt this point, the only two possible errors are\nERROR_DIRECTORY or ERROR_BAD_PATHNAME.\n\nThis code clarifies this and also saves a call to\nerr_win_to_posix.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY\n    \n    At this point, the only two possible errors are ERROR_DIRECTORY or\n    ERROR_BAD_PATHNAME.\n    \n    This code clarifies this and also saves a call to err_win_to_posix.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1402%2FAtariDreams%2Fopendir-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1402/AtariDreams/opendir-v1\nPull-Request: https://github.com/git/git/pull/1402\n\n compat/win32/dirent.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nindex 52420ec7d4d..8f94a5ab6db 100644\n--- a/compat/win32/dirent.c\n+++ b/compat/win32/dirent.c\n@@ -34,13 +34,13 @@ DIR *opendir(const char *name)\n \tif (len && !is_dir_sep(pattern[len - 1]))\n \t\tpattern[len++] = '/';\n \tpattern[len++] = '*';\n-\tpattern[len] = 0;\n+\tpattern[len] = '\\0';\n \n \t/* open find handle */\n \th = FindFirstFileW(pattern, &fdata);\n \tif (h == INVALID_HANDLE_VALUE) {\n \t\tDWORD err = GetLastError();\n-\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);\n+\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : ENOENT;\n \t\treturn NULL;\n \t}\n \n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"},{"id":"469299","messageId":"pull.1402.v2.git.git.1671466826159.gitgitgadget@gmail.com","threadId":"58980","inReplyTo":"pull.1402.git.git.1671465108414.gitgitgadget@gmail.com","subject":"[PATCH v2] win32: explicitly set errno to enoent if err is not error_directory","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-19T16:20:26Z","receivedAt":"2022-12-19T16:20:34Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nAt this point, the only two possible errors are\nERROR_DIRECTORY or ERROR_BAD_PATHNAME.\n\nThis code clarifies this and also saves a call to\nerr_win_to_posix.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    win32: explicitly set errno to enoent if err is not error_directory\n    \n    At this point, the only two possible errors are ERROR_DIRECTORY or\n    ERROR_BAD_PATHNAME.\n    \n    This code clarifies this and also saves a call to err_win_to_posix.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1402%2FAtariDreams%2Fopendir-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1402/AtariDreams/opendir-v2\nPull-Request: https://github.com/git/git/pull/1402\n\nRange-diff vs v1:\n\n 1:  6e66c0deaf9 ! 1:  bf757aee0be Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY\n     @@ Metadata\n      Author: Seija Kijin <doremylover123@gmail.com>\n      \n       ## Commit message ##\n     -    Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY\n     +    win32: explicitly set errno to enoent if err is not error_directory\n      \n          At this point, the only two possible errors are\n          ERROR_DIRECTORY or ERROR_BAD_PATHNAME.\n\n\n compat/win32/dirent.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\nindex 52420ec7d4d..8f94a5ab6db 100644\n--- a/compat/win32/dirent.c\n+++ b/compat/win32/dirent.c\n@@ -34,13 +34,13 @@ DIR *opendir(const char *name)\n \tif (len && !is_dir_sep(pattern[len - 1]))\n \t\tpattern[len++] = '/';\n \tpattern[len++] = '*';\n-\tpattern[len] = 0;\n+\tpattern[len] = '\\0';\n \n \t/* open find handle */\n \th = FindFirstFileW(pattern, &fdata);\n \tif (h == INVALID_HANDLE_VALUE) {\n \t\tDWORD err = GetLastError();\n-\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);\n+\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : ENOENT;\n \t\treturn NULL;\n \t}\n \n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"},{"id":"469307","messageId":"221219.86mt7jxmwd.gmgdl@evledraar.gmail.com","threadId":"58980","inReplyTo":"pull.1402.git.git.1671465108414.gitgitgadget@gmail.com","subject":"Re: [PATCH] Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-19T18:33:52Z","receivedAt":"2022-12-19T18:38:29Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Dec 19 2022, Rose via GitGitGadget wrote:\n\n> From: Seija Kijin <doremylover123@gmail.com>\n>\n> At this point, the only two possible errors are\n> ERROR_DIRECTORY or ERROR_BAD_PATHNAME.\n>\n> This code clarifies this and also saves a call to\n> err_win_to_posix.\n>\n> Signed-off-by: Seija Kijin <doremylover123@gmail.com>\n> ---\n>     Explicitly set errno to ENOENT if err is not ERROR_DIRECTORY\n>     \n>     At this point, the only two possible errors are ERROR_DIRECTORY or\n>     ERROR_BAD_PATHNAME.\n>     \n>     This code clarifies this and also saves a call to err_win_to_posix.\n>     \n>     Signed-off-by: Seija Kijin doremylover123@gmail.com\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1402%2FAtariDreams%2Fopendir-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1402/AtariDreams/opendir-v1\n> Pull-Request: https://github.com/git/git/pull/1402\n>\n>  compat/win32/dirent.c | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\n> index 52420ec7d4d..8f94a5ab6db 100644\n> --- a/compat/win32/dirent.c\n> +++ b/compat/win32/dirent.c\n> @@ -34,13 +34,13 @@ DIR *opendir(const char *name)\n>  \tif (len && !is_dir_sep(pattern[len - 1]))\n>  \t\tpattern[len++] = '/';\n>  \tpattern[len++] = '*';\n> -\tpattern[len] = 0;\n> +\tpattern[len] = '\\0';\n\nMaybe the subject of this patch is a good change (I have no idea, and\ndon't use Windows), but this just seems like unrelated general cleanup.\n\nI think it's probably good to change these sorts cases from 0 to '\\0',\nbut let's do that as a seperate change...\n"},{"id":"469355","messageId":"2c0c8ead-3942-6c44-b854-5980cff55755@kdbg.org","threadId":"58980","inReplyTo":"pull.1402.v2.git.git.1671466826159.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] win32: explicitly set errno to enoent if err is not error_directory","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-12-20T07:21:59Z","receivedAt":"2022-12-20T07:22:10Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 19.12.22 um 17:20 schrieb Rose via GitGitGadget:\n> From: Seija Kijin <doremylover123@gmail.com>\n> \n> At this point, the only two possible errors are\n> ERROR_DIRECTORY or ERROR_BAD_PATHNAME.\n> \n> This code clarifies this and also saves a call to\n> err_win_to_posix.\n> \n> Signed-off-by: Seija Kijin <doremylover123@gmail.com>\n> ---\n\n> diff --git a/compat/win32/dirent.c b/compat/win32/dirent.c\n> index 52420ec7d4d..8f94a5ab6db 100644\n> --- a/compat/win32/dirent.c\n> +++ b/compat/win32/dirent.c\n> @@ -34,13 +34,13 @@ DIR *opendir(const char *name)\n>  \tif (len && !is_dir_sep(pattern[len - 1]))\n>  \t\tpattern[len++] = '/';\n>  \tpattern[len++] = '*';\n> -\tpattern[len] = 0;\n> +\tpattern[len] = '\\0';\n>  \n>  \t/* open find handle */\n>  \th = FindFirstFileW(pattern, &fdata);\n>  \tif (h == INVALID_HANDLE_VALUE) {\n>  \t\tDWORD err = GetLastError();\n> -\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : err_win_to_posix(err);\n> +\t\terrno = (err == ERROR_DIRECTORY) ? ENOTDIR : ENOENT;\n\nThis change does not look correct. The documentation of\nFindFirstFileW()[*] does not give any guarantees that ERROR_DIRECTORY\nand ERROR_BAD_PATHNAME are the only possible error values. It is\ncertainly not unthinkable that a hardware error is reported as\nERROR_IO_DEVICE and should be translated to EIO.\n\n[*]\nhttps://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilew\n\n-- Hannes\n\n"}]}