mingw_fopen: report ENOENT for invalid file names
authorJohannes Sixt <j6t@kdbg.org>
Mon, 29 May 2017 20:27:35 +0000 (22:27 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Jun 2017 01:40:04 +0000 (10:40 +0900)
On Windows, certain characters are prohibited in file names, most
prominently the colon. When fopen() is called with such an invalid file
name, the underlying Windows API actually reports a particular error,
but since there is no suitable errno value, this error is translated
to EINVAL. Detect the case and report ENOENT instead.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c
t/t5580-clone-push-unc.sh
index 3fbfda5978b7bb715ab132283a69fa49384896e9..b604a827e88249ea003ffa685026a7d78436dbd4 100644 (file)
@@ -423,6 +423,8 @@ FILE *mingw_fopen (const char *filename, const char *otype)
                return NULL;
        }
        file = _wfopen(wfilename, wotype);
+       if (!file && GetLastError() == ERROR_INVALID_NAME)
+               errno = ENOENT;
        if (file && hide && set_hidden_flag(wfilename, 1))
                warning("could not mark '%s' as hidden.", filename);
        return file;
index 944730cddc0f7757ed8484ef37b06adc7fe422cd..b322c2f72202fbfda5c74f8d085744dd29c55fb3 100755 (executable)
@@ -45,7 +45,7 @@ test_expect_success push '
        test "$rev" = "$(git rev-parse --verify refs/heads/to-push)"
 '
 
-test_expect_failure 'remote nick cannot contain backslashes' '
+test_expect_success 'remote nick cannot contain backslashes' '
        BACKSLASHED="$(pwd | tr / \\\\)" &&
        git ls-remote "$BACKSLASHED" >out 2>err &&
        test_i18ngrep ! "unable to access" err