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

From: "Ota, Takaaki" <[email-masked]>
Date: Mon, 29 Feb 2016 11:28:15 -0800

Mon, 29 Feb 2016 20:48:30 +0200: Eli Zaretskii <[email-masked]> wrote:

> > Date: Mon, 29 Feb 2016 10:05:26 -0800
> > CC: <[email-masked]>
> > From: "Ota, Takaaki" <[email-masked]>
> > 
> > I set a break pointer at write_region() in fileio.c and then perform
> > the save-buffer command.  When emacs breaks at write_region() on 24.5
> > the file's permission is changed to writable while on 25.0.91 the
> > permission remains read-only.
> 
> Both results are wrong: the file should not exist when write_region is
> called, because Emacs renamed it to the backup-file name.  The problem
> is most probably in making the backup, so I suggest looking at
> sys_rename instead.
> 

emacs-24.5 never called sys_rename().

emacs-25.0.91 calls sys_rename() but strangely old name and the new
name are the same.  See below.

-Tak

Breakpoint 1, sys_rename (old=0x880c9b8 "c:/d/ota/memo", 
    new=0x880c9b8 "c:/d/ota/memo") at w32.c:4543
4543    {
(gdb) n
4544      return sys_rename_replace (old, new, TRUE);
(gdb) s
sys_rename_replace (oldname=oldname@entry=0x880c9b8 "c:/d/ota/memo", 
    newname=newname@entry=0x880c9b8 "c:/d/ota/memo", force=force@entry=1)
    at w32.c:4404
4404      strcpy (temp, map_w32_filename (oldname, NULL));
(gdb) n
4407      oldname_dev = volume_info.serialnum;
(gdb) 
4409      if (os_subtype == OS_9X)
(gdb) 
4416          oldname = map_w32_filename (oldname, NULL);
(gdb) 
4409      if (os_subtype == OS_9X)
(gdb) 
4455      newname = map_w32_filename (newname, NULL);
(gdb) 
4458      newname_dev = volume_info.serialnum;
(gdb) 
4460      if (w32_unicode_filenames)
(gdb) 
4464          filename_to_utf16 (temp, temp_w);
(gdb) 
4465          filename_to_utf16 (newname, newname_w);
(gdb) 
4466          result = _wrename (temp_w, newname_w);
(gdb) p temp
$12 = "c:\\d\\ota\\memo\000\210\000Jº>w`P©\000\000\000¨\000\000\000¨\000Jº>w`P©\000<Þ\210\000h'Iw8\001¨\000L'IwÀ9]o\000\000¨\000\000\000¨\000\000\000\000\000\000\000¨\000\000\000\000\000\000\000\001\001\bÞ\210\000\000\000\000\000 ß\210\000%cCwì5ë\030þÿÿÿL'Iw¢²Dw\000\000¨\000c\000\000Pí0?wÌ8]o\000\000\000\000\000\000¨\000hP©", '\000' <repeats 39 times>, "¨", '\000' <repeats 41 times>...
(gdb) p temp_w
$13 = L"c:\\d\\ota\\memo\000\120\177ª\025\000G\000\354\023\100\001G\000\030\304\034\001\025\000\260\001\001\220\122©\000\000\002\x604\x2490¨\304\001\004\301\270\023\100\001\030\304\034\001\000\000\177\000\030\304\034\001\xf613\xe104\050\002\000\000\000\032\000\143\001\000\120\036\000\150\120©\150\120©\143\120©\000\000\000\000\000¨\a\x300\xd9a0\210\070\201\034\001\xdb30\210\045\143\103\167\014\056\x18eb\xfffe\xffff\026\065\077\167\101\065\077\167\032\002\000\070\002\000\142\120©\140\120©\032\002\000\000¨\001\000\005\000\xe440\x80a\xe24c\x80a\143\072\\\000\000\xdb64\210\250\066\067\001\030\000\x2158\xff40\xdb50\210\246\264\017\001\006\000\xdb50\210\xdaf8\210\x17be\111\167\000¨\000\000\032\002\000\000¨\001\000\004\000\000\000\140\120©\000\000\000¨\xdb40\210\102\040\111\167\070\001¨…\111\167\274\074\135\157\000\000\000\000\000¨\002\000\000\000\150\120©\xdb64\210\001\xdb08\210\222\256\022\001\xdc14\210\045\143\103\167\074\066\x18eb\xfffe\xffff…\111\167\206\265\104\167\000¨\143\001\000\120"...
(gdb) p newname
$14 = 0x1404ce0 <shortname.46207> "c:\\d\\ota\\memo"
(gdb) p newname_w
$15 = L"c:\\d\\ota\\memo\000\xdcd0\210\000\000\032\034\xdcd0\210\002\000\xdc9c\210\xe322\076\167\066\263\077\167\140\073\135\157\000\000\010\002\000\150\120©\304\377\210\045\143\103\167\000\000\xfffe\xffff\r\000\032\034\xdfd8\210\000\000\002\000\000\000\032\000\000\000\032\000\xdd1a\210\xdfd8\210C\000\001\032\010\002\xdd00\210\xdff2\210\000\000\000\000\000\000\120\001¨\003\000\032\000\204\006\100\001c\000\140\073\135\157\xdc04\210\001\000\304\377\210\045\143\103\167\000\000\114\152\332\005\375\271\015\001\114\152\332\005\000\000\001\000\032\000\150\120©\002\000\204\006\100\001c\000\x650\100\001 \000\270\001\000\314\311\x880\000\000\000\000\004\000\xddd4\210\x650\100\001\x650\100\001\210\007\100\001\000\144\130\001\114\152\332\005\000\000\210\145\130\001\106\307\015\001\140\006\100\001\000\000\000\000\314\311\x880        \000\000\000\000\000\000\000    \000\120\001¨\000¨\000\144\130\001\114\152\332\005\000\000\210\145\130\001\122\102\015\001\140\006\100\001\314\311\x880       \000\000\000    \000\000\000\000\000\000\000\000\000"...
(gdb) n
[New Thread 10660.0x29f4]
[New Thread 10660.0x2904]
4467          if (result < 0 && force)
(gdb) p result
$16 = 0
(gdb) n
4527                    return result;
(gdb) 
4539    }
(gdb) 
sys_rename (old=0x880c9b8 "c:/d/ota/memo", new=0x880c9b8 "c:/d/ota/memo")
    at w32.c:4545
4545    }