Subject: Re: bug#22795: 25.0.91; Can't write read only file on w32

From: Eli Zaretskii <[email-masked]>
Date: Mon, 29 Feb 2016 20:31:39 +0200

> Date: Mon, 29 Feb 2016 09:53:54 -0800
> CC: <[email-masked]>
> From: "Ota, Takaaki" <[email-masked]>
> 
> > Does the file that Emacs tries to open here, c:\d\ota\memo, exist when
> > _wopen is called, and if so, is it read-only?  Please check this with
> > both versions of Emacs, and see if there's any differences in what
> > happens.
> 
> In both cases the original file exists right before calling _wopen()
> but there is a difference.  On 25.0.91 the file remains read-only but
> on 24.5 the file is writable right before calling _open().  Now we
> have some clue here.

The file shouldn't exist at this point, because Emacs renamed it to a
backup file.  This is what I see here: the first call to _wopen,
without _O_CREAT, fails, and we then call _wopen again with _O_CREAT,
which creates the file.

If during the first call to sys_open the file already exists, then the
problem is not in sys_open, the problem is when the file is backed-up,
which should involve sys_rename.  If you put a breakpoint inside
sys_rename, you should see it called after you type "C-x C-s" to save
the file and answer the question Emacs displays about the file being
write-protected.  Please step through sys_rename_replace and see what
happens there, perhaps the code there fails to detect that the file is
read-only and remove the RO bit before renaming.