From: Johannes Schindelin Date: Tue, 17 Dec 2024 12:52:04 +0000 (+0000) Subject: mingw_rename: do support directory renames X-Git-Tag: v2.48.0-rc1~16^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b30404dfc04a4b087b630aea4ab88a51cd3a7459;p=thirdparty%2Fgit.git mingw_rename: do support directory renames In 391bceae435 (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 Signed-off-by: Junio C Hamano --- diff --git a/compat/mingw.c b/compat/mingw.c index c4320769db..e8f491d03a 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2273,7 +2273,7 @@ repeat: old_handle = CreateFileW(wpold, DELETE, FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (old_handle == INVALID_HANDLE_VALUE) { errno = err_win_to_posix(GetLastError()); return -1;