@@ -538,6 +538,7 @@ static int is_local_named_pipe_path(const char *filename)
538
538
539
539
int mingw_open (const char * filename , int oflags , ...)
540
540
{
541
+ static int append_atomically = -1 ;
541
542
typedef int (* open_fn_t )(wchar_t const * wfilename , int oflags , ...);
542
543
va_list args ;
543
544
unsigned mode ;
@@ -554,7 +555,16 @@ int mingw_open (const char *filename, int oflags, ...)
554
555
return -1 ;
555
556
}
556
557
557
- if ((oflags & O_APPEND ) && !is_local_named_pipe_path (filename ))
558
+ /*
559
+ * Only set append_atomically to default value(1) when repo is initialized
560
+ * and fail to get config value
561
+ */
562
+ if (append_atomically < 0 && the_repository && the_repository -> commondir &&
563
+ git_config_get_bool ("windows.appendatomically" , & append_atomically ))
564
+ append_atomically = 1 ;
565
+
566
+ if (append_atomically && (oflags & O_APPEND ) &&
567
+ !is_local_named_pipe_path (filename ))
558
568
open_fn = mingw_open_append ;
559
569
else
560
570
open_fn = _wopen ;
@@ -703,8 +713,26 @@ ssize_t mingw_write(int fd, const void *buf, size_t len)
703
713
HANDLE h = (HANDLE ) _get_osfhandle (fd );
704
714
if (GetFileType (h ) == FILE_TYPE_PIPE )
705
715
errno = EPIPE ;
706
- else
716
+ else {
717
+ wchar_t path [MAX_LONG_PATH ];
718
+ DWORD ret = GetFinalPathNameByHandleW (h , path ,
719
+ ARRAY_SIZE (path ), 0 );
720
+ UINT drive_type = ret > 0 && ret < ARRAY_SIZE (path ) ?
721
+ GetDriveTypeW (path ) : DRIVE_UNKNOWN ;
722
+
723
+ /*
724
+ * The default atomic append causes such an error on
725
+ * network file systems, in such a case, it should be
726
+ * turned off via config.
727
+ *
728
+ * `drive_type` of UNC path: DRIVE_NO_ROOT_DIR
729
+ */
730
+ if (DRIVE_NO_ROOT_DIR == drive_type || DRIVE_REMOTE == drive_type )
731
+ warning ("invalid write operation detected; you may try:\n"
732
+ "\n\tgit config windows.appendAtomically false" );
733
+
707
734
errno = EINVAL ;
735
+ }
708
736
}
709
737
710
738
return result ;
0 commit comments