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