Skip to content

Commit 97496bb

Browse files
sunzhuoshidscho
andcommitted
Add config option "windows.appendatomically" support
Atomic append on windows is only supported on local disk files, and it may cause errors in other situations, e.g. pipeline and network file system. If that is the case, this config option should be used to turn atomic append off. Signed-off-by: sunzhuoshi <[email protected]> Co-Authored-By: Johannes Schindelin <[email protected]>
1 parent c08c0b5 commit 97496bb

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

compat/mingw.c

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -741,50 +741,9 @@ 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-
786744
int mingw_open (const char *filename, int oflags, ...)
787745
{
746+
static int append_atomically = -1;
788747
typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
789748
va_list args;
790749
unsigned mode;
@@ -801,7 +760,15 @@ int mingw_open (const char *filename, int oflags, ...)
801760
return -1;
802761
}
803762

804-
if ((oflags & O_APPEND) && is_local_disk_file(filename))
763+
if (append_atomically < 0) {
764+
append_atomically = 1; /* default to `true` */
765+
if (the_repository)
766+
git_config_get_bool("windows.appendatomically",
767+
&append_atomically);
768+
}
769+
770+
if (append_atomically && (oflags & O_APPEND) &&
771+
!is_local_named_pipe_path(filename))
805772
open_fn = mingw_open_append;
806773
else
807774
open_fn = _wopen;

0 commit comments

Comments
 (0)