From: Patrick Steinhardt <ps@pks.im>
To: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 1/2] mingw: optionally use legacy (non-POSIX) delete semantics
Date: Mon, 4 May 2026 16:12:29 +0200 [thread overview]
Message-ID: <afipTWyj2zVYYqMz@pks.im> (raw)
In-Reply-To: <97508e91b62c91b77447dbba39a84770682591a8.1777380768.git.gitgitgadget@gmail.com>
On Tue, Apr 28, 2026 at 12:52:47PM +0000, Johannes Schindelin via GitGitGadget wrote:
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 2023c16db6..04f9aa3922 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -449,20 +449,63 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf)
> return wbuf;
> }
>
> +/*
> + * Use SetFileInformationByHandle(FileDispositionInfo) to force legacy
> + * (non-POSIX) delete semantics. On Windows 11, DeleteFileW() uses POSIX
> + * delete semantics internally, allowing deletion even with active
> + * MapViewOfFile views. This helper simulates Windows 10 behavior where
> + * deletion fails if a file mapping exists.
> + *
> + * Returns nonzero on success (like DeleteFileW), 0 on failure.
> + */
> +static int legacy_delete_file(const wchar_t *wpathname)
> +{
> + FILE_DISPOSITION_INFO fdi = { TRUE };
> + DWORD gle;
> + HANDLE h = CreateFileW(wpathname, DELETE,
> + FILE_SHARE_READ | FILE_SHARE_WRITE |
> + FILE_SHARE_DELETE,
> + NULL, OPEN_EXISTING,
> + FILE_FLAG_OPEN_REPARSE_POINT, NULL);
> + if (h == INVALID_HANDLE_VALUE)
> + return 0;
> +
> + if (SetFileInformationByHandle(h, FileDispositionInfo,
> + &fdi, sizeof(fdi))) {
> + CloseHandle(h);
> + return 1;
> + }
> + gle = GetLastError();
> + CloseHandle(h);
> + SetLastError(gle);
> + return 0;
> +}
> +
> +static int try_delete_file(const wchar_t *wpathname, int use_legacy)
> +{
> + if (use_legacy)
> + return legacy_delete_file(wpathname);
> + return DeleteFileW(wpathname);
> +}
> +
> int mingw_unlink(const char *pathname, int handle_in_use_error)
> {
> + static int use_legacy_delete = -1;
> int tries = 0;
> wchar_t wpathname[MAX_PATH];
> if (xutftowcs_path(wpathname, pathname) < 0)
> return -1;
>
> - if (DeleteFileW(wpathname))
> + if (use_legacy_delete < 0)
> + use_legacy_delete = !!getenv("GIT_TEST_LEGACY_DELETE");
Should this use `git_env_bool()`?
Patrick
next prev parent reply other threads:[~2026-05-04 14:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 12:52 [PATCH 0/2] maintenance(geometric): avoid deadlocks on Windows 10 Johannes Schindelin via GitGitGadget
2026-04-28 12:52 ` [PATCH 1/2] mingw: optionally use legacy (non-POSIX) delete semantics Johannes Schindelin via GitGitGadget
2026-05-04 14:12 ` Patrick Steinhardt [this message]
2026-05-07 12:49 ` Johannes Schindelin
2026-04-28 12:52 ` [PATCH 2/2] maintenance(geometric): do release the `.idx` files before repacking Johannes Schindelin via GitGitGadget
2026-04-28 15:01 ` [PATCH 0/2] maintenance(geometric): avoid deadlocks on Windows 10 Derrick Stolee
2026-05-04 14:12 ` Patrick Steinhardt
2026-05-07 12:51 ` [PATCH v2 " Johannes Schindelin via GitGitGadget
2026-05-07 12:51 ` [PATCH v2 1/2] mingw: optionally use legacy (non-POSIX) delete semantics Johannes Schindelin via GitGitGadget
2026-05-07 12:51 ` [PATCH v2 2/2] maintenance(geometric): do release the `.idx` files before repacking Johannes Schindelin via GitGitGadget
2026-05-08 13:20 ` [PATCH v2 0/2] maintenance(geometric): avoid deadlocks on Windows 10 Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afipTWyj2zVYYqMz@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox