20
20
#define SECURITY_WIN32
21
21
#include <sspi.h>
22
22
#include "../write-or-die.h"
23
+ #include "../repository.h"
23
24
24
25
#define HCAST (type , handle ) ((type)(intptr_t)handle)
25
26
@@ -546,6 +547,7 @@ static int is_local_named_pipe_path(const char *filename)
546
547
547
548
int mingw_open (const char * filename , int oflags , ...)
548
549
{
550
+ static int append_atomically = -1 ;
549
551
typedef int (* open_fn_t )(wchar_t const * wfilename , int oflags , ...);
550
552
va_list args ;
551
553
unsigned mode ;
@@ -562,7 +564,16 @@ int mingw_open (const char *filename, int oflags, ...)
562
564
return -1 ;
563
565
}
564
566
565
- if ((oflags & O_APPEND ) && !is_local_named_pipe_path (filename ))
567
+ /*
568
+ * Only set append_atomically to default value(1) when repo is initialized
569
+ * and fail to get config value
570
+ */
571
+ if (append_atomically < 0 && the_repository && the_repository -> commondir &&
572
+ git_config_get_bool ("windows.appendatomically" , & append_atomically ))
573
+ append_atomically = 1 ;
574
+
575
+ if (append_atomically && (oflags & O_APPEND ) &&
576
+ !is_local_named_pipe_path (filename ))
566
577
open_fn = mingw_open_append ;
567
578
else
568
579
open_fn = _wopen ;
@@ -711,8 +722,26 @@ ssize_t mingw_write(int fd, const void *buf, size_t len)
711
722
HANDLE h = (HANDLE ) _get_osfhandle (fd );
712
723
if (GetFileType (h ) == FILE_TYPE_PIPE )
713
724
errno = EPIPE ;
714
- else
725
+ else {
726
+ wchar_t path [MAX_PATH ];
727
+ DWORD ret = GetFinalPathNameByHandleW (h , path ,
728
+ ARRAY_SIZE (path ), 0 );
729
+ UINT drive_type = ret > 0 && ret < ARRAY_SIZE (path ) ?
730
+ GetDriveTypeW (path ) : DRIVE_UNKNOWN ;
731
+
732
+ /*
733
+ * The default atomic append causes such an error on
734
+ * network file systems, in such a case, it should be
735
+ * turned off via config.
736
+ *
737
+ * `drive_type` of UNC path: DRIVE_NO_ROOT_DIR
738
+ */
739
+ if (DRIVE_NO_ROOT_DIR == drive_type || DRIVE_REMOTE == drive_type )
740
+ warning ("invalid write operation detected; you may try:\n"
741
+ "\n\tgit config windows.appendAtomically false" );
742
+
715
743
errno = EINVAL ;
744
+ }
716
745
}
717
746
718
747
return result ;
0 commit comments