public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/98985] New: libstdc++: filesystem::rename not overwriting files on Windows
@ 2021-02-07 16:58 m.heinzler at heinzler dot de
  2021-02-09 14:55 ` [Bug libstdc++/98985] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: m.heinzler at heinzler dot de @ 2021-02-07 16:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98985

            Bug ID: 98985
           Summary: libstdc++: filesystem::rename not overwriting files on
                    Windows
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.heinzler at heinzler dot de
  Target Milestone: ---

Created attachment 50139
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50139&action=edit
Proposed fix

filesystem::rename must replace existing files and currently does so on most
platforms by simply calling posix::rename. But on Windows (specifically MinGW),
posix::rename refers to Microsoft's MSVCRT which does not overwrite files.
See:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rename-wrename?view=msvc-160

I attached a patch that falls back to the WinAPI in this case and tested it
successfully. This is also how Microsoft implements filesystem::rename.

As I'm not familiar with the codebase I wasn't able to add a simple test case
for this. If someone could give me a hint which files to touch I could also
work on that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/98985] libstdc++: filesystem::rename not overwriting files on Windows
  2021-02-07 16:58 [Bug libstdc++/98985] New: libstdc++: filesystem::rename not overwriting files on Windows m.heinzler at heinzler dot de
@ 2021-02-09 14:55 ` redi at gcc dot gnu.org
  2021-02-09 21:09 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-09 14:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98985

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-02-09
     Ever confirmed|0                           |1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/98985] libstdc++: filesystem::rename not overwriting files on Windows
  2021-02-07 16:58 [Bug libstdc++/98985] New: libstdc++: filesystem::rename not overwriting files on Windows m.heinzler at heinzler dot de
  2021-02-09 14:55 ` [Bug libstdc++/98985] " redi at gcc dot gnu.org
@ 2021-02-09 21:09 ` redi at gcc dot gnu.org
  2021-02-10 11:01 ` m.heinzler at heinzler dot de
  2021-04-19 10:32 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-02-09 21:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98985

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'll fix it by using MoveFileExW in posix::rename instead.

MoveFileExW seems to have some weird differences from POSIX rename when the
source or destination name is a directory.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/98985] libstdc++: filesystem::rename not overwriting files on Windows
  2021-02-07 16:58 [Bug libstdc++/98985] New: libstdc++: filesystem::rename not overwriting files on Windows m.heinzler at heinzler dot de
  2021-02-09 14:55 ` [Bug libstdc++/98985] " redi at gcc dot gnu.org
  2021-02-09 21:09 ` redi at gcc dot gnu.org
@ 2021-02-10 11:01 ` m.heinzler at heinzler dot de
  2021-04-19 10:32 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: m.heinzler at heinzler dot de @ 2021-02-10 11:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98985

--- Comment #2 from m.heinzler at heinzler dot de <m.heinzler at heinzler dot de> ---
(In reply to Jonathan Wakely from comment #1)
> I'll fix it by using MoveFileExW in posix::rename instead.
> 
> MoveFileExW seems to have some weird differences from POSIX rename when the
> source or destination name is a directory.

Yes, after taking another look that seems much better suited there.

I don't know about all the differences but as the currently used Microsoft
implementation of rename is also far from POSIX compliant I'd guess this is a
project for another day :). At least I have not stumbled upon any issues
related to that yet.

Thank you!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/98985] libstdc++: filesystem::rename not overwriting files on Windows
  2021-02-07 16:58 [Bug libstdc++/98985] New: libstdc++: filesystem::rename not overwriting files on Windows m.heinzler at heinzler dot de
                   ` (2 preceding siblings ...)
  2021-02-10 11:01 ` m.heinzler at heinzler dot de
@ 2021-04-19 10:32 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-19 10:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98985

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |10.3

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk by r11-7221 and gcc-10 by r10-9590

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-19 10:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-07 16:58 [Bug libstdc++/98985] New: libstdc++: filesystem::rename not overwriting files on Windows m.heinzler at heinzler dot de
2021-02-09 14:55 ` [Bug libstdc++/98985] " redi at gcc dot gnu.org
2021-02-09 21:09 ` redi at gcc dot gnu.org
2021-02-10 11:01 ` m.heinzler at heinzler dot de
2021-04-19 10:32 ` redi at gcc dot gnu.org

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 read-only IMAP folder(s) and NNTP newsgroup(s).