Skip to content

Commit 033f99e

Browse files
committed
Fix append failure issue under remote directories git-for-windows#2753
1 parent 9b2e006 commit 033f99e

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

compat/mingw.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,48 @@ static int is_local_named_pipe_path(const char *filename)
741741
filename[9]);
742742
}
743743

744+
static int is_local_disk_file(const char *filename)
745+
{
746+
wchar_t wpath[MAX_LONG_PATH];
747+
wchar_t wfullpath[MAX_LONG_PATH];
748+
size_t windex;
749+
750+
if (is_local_named_pipe_path(filename))
751+
return 0;
752+
753+
/*
754+
* Do everything in wide chars because the drive letter might be
755+
* a multi-byte sequence. See win32_has_dos_drive_prefix().
756+
*/
757+
if (xutftowcs_long_path(wpath, filename) < 0)
758+
return 0;
759+
760+
/*
761+
* GetDriveTypeW() requires a final slash.
762+
*/
763+
windex = wcslen(wpath) - 1;
764+
while (windex >= 0) {
765+
if (is_dir_sep(wpath[windex]))
766+
break;
767+
windex--;
768+
}
769+
wpath[windex++] = L'\\';
770+
wpath[windex] = 0;
771+
772+
/*
773+
* Normalize the path. If nothing else, this converts forward
774+
* slashes to backslashes. This is essential to get GetDriveTypeW()
775+
* correctly handle some UNC "\\server\share\..." paths.
776+
*/
777+
if (!GetFullPathNameW(wpath, MAX_LONG_PATH, wfullpath, NULL))
778+
return 0;
779+
780+
if (GetDriveTypeW(wfullpath) == DRIVE_REMOTE)
781+
return 0;
782+
783+
return 1;
784+
}
785+
744786
int mingw_open (const char *filename, int oflags, ...)
745787
{
746788
typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
@@ -759,7 +801,7 @@ int mingw_open (const char *filename, int oflags, ...)
759801
return -1;
760802
}
761803

762-
if ((oflags & O_APPEND) && !is_local_named_pipe_path(filename))
804+
if ((oflags & O_APPEND) && is_local_disk_file(filename))
763805
open_fn = mingw_open_append;
764806
else
765807
open_fn = _wopen;

0 commit comments

Comments
 (0)