From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Johannes Sixt <j6t@kdbg.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 2/2] compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL`
Date: Thu, 13 Mar 2025 11:02:55 -0700 [thread overview]
Message-ID: <xmqqjz8solkg.fsf@gitster.g> (raw)
In-Reply-To: <20250313-b4-pks-mingw-lockfile-flake-v1-2-bc5d3e70f516@pks.im> (Patrick Steinhardt's message of "Thu, 13 Mar 2025 15:17:44 +0100")
Patrick Steinhardt <ps@pks.im> writes:
> + /*
> + * 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.
> + 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))
next prev parent reply other threads:[~2025-03-13 18:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 14:17 [PATCH 0/2] compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL` Patrick Steinhardt
2025-03-13 14:17 ` [PATCH 1/2] compat/mingw: handle O_CLOEXEC in `mingw_open_existing()` Patrick Steinhardt
2025-03-13 17:52 ` Junio C Hamano
2025-03-13 14:17 ` [PATCH 2/2] compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL` Patrick Steinhardt
2025-03-13 18:02 ` Junio C Hamano [this message]
2025-03-16 0:01 ` Johannes Schindelin
2025-03-17 15:16 ` Patrick Steinhardt
2025-03-20 10:37 ` [PATCH v2 0/2] " Patrick Steinhardt
2025-03-20 10:37 ` [PATCH v2 1/2] meson: fix compat sources when compiling with MSVC Patrick Steinhardt
2025-03-20 10:37 ` [PATCH v2 2/2] compat/mingw: fix EACCESS when opening files with `O_CREAT | O_EXCL` Patrick Steinhardt
2025-03-26 12:20 ` Johannes Schindelin
2025-03-28 9:20 ` Patrick Steinhardt
2025-03-28 15:41 ` Johannes Schindelin
2025-03-31 6:57 ` 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=xmqqjz8solkg.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=ps@pks.im \
/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;
as well as URLs for NNTP newsgroup(s).