This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: rename2 check for existing file
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-developers at cygwin dot com" <cygwin-developers at cygwin dot com>
- Date: Wed, 9 Jan 2019 20:37:05 +0000
- Subject: Re: rename2 check for existing file
- References: <20190109145249.GM593@calimero.vinschen.de>
Hi Corinna,
On 1/9/2019 9:52 AM, Corinna Vinschen wrote:
> Hi Ken,
>
> your patch to support renameat2(..., RENAME_NOREPLACE),
> commit f665b1cef30f9032877081ac63ea94910825be6a, also
> introduced a new check
>
> + /* Should we replace an existing file? */
> + if ((removepc || dstpc->exists ()) && noreplace)
> + {
> + set_errno (EEXIST);
> + __leave;
> + }
>
> However, the noreplace flag also adds the same check to the actual
> NtSetInformationFile call to rename the file:
>
> - pfri->ReplaceIfExists = TRUE;
> + pfri->ReplaceIfExists = !noreplace;
>
> So, isn't the first check redundant? Can't we just drop it? The
> rename2 function already has so many checks to perform before actually
> calling NtSetInformationFile, every check we can remove is a boon, I
> think.
My recollection is that that we discussed this at the time and decided that
there was a border case where the check was still needed in order to make sure
that EEXIST was set. I'll have to look back at the email thread and see if I
can reconstruct the reason. I may not have a chance to do that until tomorrow.
Ken