зеркало из https://github.com/microsoft/git.git
Merge pull request #3646 from sunzhuoshi/main
Fix append failure issue under remote directories #2753
This commit is contained in:
Коммит
989c3a6832
|
@ -539,4 +539,6 @@ include::config/versionsort.txt[]
|
|||
|
||||
include::config/web.txt[]
|
||||
|
||||
include::config/windows.txt[]
|
||||
|
||||
include::config/worktree.txt[]
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
windows.appendAtomically::
|
||||
By default, append atomic API is used on windows. But it works only with
|
||||
local disk files, if you're working on a network file system, you should
|
||||
set it false to turn it off.
|
|
@ -745,6 +745,7 @@ static int is_local_named_pipe_path(const char *filename)
|
|||
|
||||
int mingw_open (const char *filename, int oflags, ...)
|
||||
{
|
||||
static int append_atomically = -1;
|
||||
typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
|
||||
va_list args;
|
||||
unsigned mode;
|
||||
|
@ -761,7 +762,16 @@ int mingw_open (const char *filename, int oflags, ...)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ((oflags & O_APPEND) && !is_local_named_pipe_path(filename))
|
||||
/*
|
||||
* Only set append_atomically to default value(1) when repo is initialized
|
||||
* and fail to get config value
|
||||
*/
|
||||
if (append_atomically < 0 && the_repository && the_repository->commondir &&
|
||||
git_config_get_bool("windows.appendatomically", &append_atomically))
|
||||
append_atomically = 1;
|
||||
|
||||
if (append_atomically && (oflags & O_APPEND) &&
|
||||
!is_local_named_pipe_path(filename))
|
||||
open_fn = mingw_open_append;
|
||||
else
|
||||
open_fn = _wopen;
|
||||
|
@ -910,8 +920,26 @@ ssize_t mingw_write(int fd, const void *buf, size_t len)
|
|||
HANDLE h = (HANDLE) _get_osfhandle(fd);
|
||||
if (GetFileType(h) == FILE_TYPE_PIPE)
|
||||
errno = EPIPE;
|
||||
else
|
||||
else {
|
||||
wchar_t path[MAX_LONG_PATH];
|
||||
DWORD ret = GetFinalPathNameByHandleW(h, path,
|
||||
ARRAY_SIZE(path), 0);
|
||||
UINT drive_type = ret > 0 && ret < ARRAY_SIZE(path) ?
|
||||
GetDriveTypeW(path) : DRIVE_UNKNOWN;
|
||||
|
||||
/*
|
||||
* The default atomic append causes such an error on
|
||||
* network file systems, in such a case, it should be
|
||||
* turned off via config.
|
||||
*
|
||||
* `drive_type` of UNC path: DRIVE_NO_ROOT_DIR
|
||||
*/
|
||||
if (DRIVE_NO_ROOT_DIR == drive_type || DRIVE_REMOTE == drive_type)
|
||||
warning("invalid write operation detected; you may try:\n"
|
||||
"\n\tgit config windows.appendAtomically false");
|
||||
|
||||
errno = EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Загрузка…
Ссылка в новой задаче