]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/win32-retry-pipe-write-on-enospc' into maint-2.43
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Feb 2024 22:44:51 +0000 (14:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Feb 2024 22:44:51 +0000 (14:44 -0800)
Update to the code that writes to pipes on Windows.

* js/win32-retry-pipe-write-on-enospc:
  win32: special-case `ENOSPC` when writing to a pipe

1  2 
compat/mingw.c

diff --combined compat/mingw.c
index 42053c1f656bd8b73696b751f30177ce9e544d59,bdb95e7ce0f2493c6bbb0c9bec8c0e9e9e7a85c9..4bcbccf01a021481e31ae7f5ccd7e51cc6f4a92d
@@@ -255,8 -255,6 +255,8 @@@ int mingw_core_config(const char *var, 
        }
  
        if (!strcmp(var, "core.unsetenvvars")) {
 +              if (!value)
 +                      return config_error_nonbool(var);
                free(unset_environment_variables);
                unset_environment_variables = xstrdup(value);
                return 0;
@@@ -707,13 -705,24 +707,24 @@@ ssize_t mingw_write(int fd, const void 
  {
        ssize_t result = write(fd, buf, len);
  
-       if (result < 0 && errno == EINVAL && buf) {
+       if (result < 0 && (errno == EINVAL || errno == ENOSPC) && buf) {
+               int orig = errno;
                /* check if fd is a pipe */
                HANDLE h = (HANDLE) _get_osfhandle(fd);
-               if (GetFileType(h) == FILE_TYPE_PIPE)
+               if (GetFileType(h) != FILE_TYPE_PIPE)
+                       errno = orig;
+               else if (orig == EINVAL)
                        errno = EPIPE;
-               else
-                       errno = EINVAL;
+               else {
+                       DWORD buf_size;
+                       if (!GetNamedPipeInfo(h, NULL, NULL, &buf_size, NULL))
+                               buf_size = 4096;
+                       if (len > buf_size)
+                               return write(fd, buf, buf_size);
+                       errno = orig;
+               }
        }
  
        return result;