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

Re: [PATCH 2/2] compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 13, 2025, 18:02 UTC
Message-ID
<xmqqjz8solkg.fsf@gitster.g>
In-Reply-To
<20250313-b4-pks-mingw-lockfile-flake-v1-2-bc5d3e70f516@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 11 quoted lines
> +	/*
> +	 * Internally, `_wopen()` uses the `CreateFile()` API with CREATE_NEW,
> +	 * which may error out with ERROR_ACCESS_DENIED when the file is
> +	 * scheduled for deletion via `DeleteFileW()`. The file essentially
> +	 * exists, so we map this error to ERROR_ALREADY_EXISTS so that callers
> +	 * don't have to special-case this.
> +	 *
> +	 * This fixes issues for example with the lockfile interface when one
> +	 * process has a lock that it is about to commit or release while
> +	 * another process wants to acquire it.
> +	 */

The above may explain how the code gets ERROR_ACCESS_DENIED when there is a pending DeleteFileW() on the file. I however cannot judge if the opposite is also always true, i.e. ERROR_ACCESS_DENIED always mean the file did exist and hasn't gone away and no other reason the code would ever get that error status. Somebody with better understanding on Windows API behaviour hopefully can review it.

Thanks.
Show 5 quoted lines
> +	if (fd < 0 && create && GetLastError() == ERROR_ACCESS_DENIED)
> +		errno = EEXIST;
>  	if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) {
>  		DWORD attrs = GetFileAttributesW(wfilename);
>  		if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
Previous: Patrick SteinhardtNext: Johannes Schindelin
Message 3 of 14 in “compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`”
  1. 0/2 compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`Patrick Steinhardt, Mar 13, 2025
  2. 2/2 compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`Patrick Steinhardt, Mar 13, 2025
  3. Junio C HamanoMar 13, 2025
  4. Johannes SchindelinMar 16, 2025
  5. Patrick SteinhardtMar 17, 2025
  6. 1/2 compat/mingw: handle O_CLOEXEC in `mingw_open_existing()`Patrick Steinhardt, Mar 13, 2025
  7. Junio C HamanoMar 13, 2025
  8. 0/2 compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`Patrick Steinhardt, Mar 20, 2025
  9. 1/2 meson: fix compat sources when compiling with MSVCPatrick Steinhardt, Mar 20, 2025
  10. 2/2 compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`Patrick Steinhardt, Mar 20, 2025
  11. Johannes SchindelinMar 26, 2025
  12. Patrick SteinhardtMar 28, 2025
  13. Johannes SchindelinMar 28, 2025
  14. Patrick SteinhardtMar 31, 2025

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.