Skip to content

Commit b30404d

Browse files
dschogitster
authored andcommitted
mingw_rename: do support directory renames
In 391bcea (compat/mingw: support POSIX semantics for atomic renames, 2024-10-27), we taught the `mingw_rename()` function to respect POSIX semantics, but we did so only as a fallback after `_wrename()` fails. This hid a bug in the implementation that was not caught by Git's test suite: The `CreateFileW()` function _can_ open handles to directories, but not when asked to use the `FILE_ATTRIBUTE_NORMAL` flag, as that flag only is allowed for files. Let's fix this by using the common `FILE_FLAG_BACKUP_SEMANTICS` flag that can be used for opening handles to directories, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 391bcea commit b30404d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compat/mingw.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ int mingw_rename(const char *pold, const char *pnew)
22732273

22742274
old_handle = CreateFileW(wpold, DELETE,
22752275
FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
2276-
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2276+
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
22772277
if (old_handle == INVALID_HANDLE_VALUE) {
22782278
errno = err_win_to_posix(GetLastError());
22792279
return -1;

0 commit comments

Comments
 (0)