git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] mingw: optionally use legacy (non-POSIX) delete semantics

From
Patrick Steinhardt <ps@pks.im>
Date
May 4, 2026, 14:12 UTC
Message-ID
<afipTWyj2zVYYqMz@pks.im>
In-Reply-To
<97508e91b62c91b77447dbba39a84770682591a8.1777380768.git.gitgitgadget@gmail.com>
On Tue, Apr 28, 2026 at 12:52:47PM +0000, Johannes Schindelin via GitGitGadget wrote:
Show 58 quoted lines
> 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
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 3 of 11 in “maintenance(geometric): avoid deadlocks on Windows 10”
  1. 0/2 maintenance(geometric): avoid deadlocks on Windows 10Johannes Schindelin via GitGitGadget, Apr 28, 2026
  2. 1/2 mingw: optionally use legacy (non-POSIX) delete semanticsJohannes Schindelin via GitGitGadget, Apr 28, 2026
  3. Patrick SteinhardtMay 4, 2026
  4. Johannes SchindelinMay 7, 2026
  5. 2/2 maintenance(geometric): do release the `.idx` files before repackingJohannes Schindelin via GitGitGadget, Apr 28, 2026
  6. Derrick StoleeApr 28, 2026
  7. Patrick SteinhardtMay 4, 2026
  8. 0/2 maintenance(geometric): avoid deadlocks on Windows 10Johannes Schindelin via GitGitGadget, May 7, 2026
  9. 1/2 mingw: optionally use legacy (non-POSIX) delete semanticsJohannes Schindelin via GitGitGadget, May 7, 2026
  10. 2/2 maintenance(geometric): do release the `.idx` files before repackingJohannes Schindelin via GitGitGadget, May 7, 2026
  11. Patrick SteinhardtMay 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.