public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6290] c++: Windows rename [PR 98412]
@ 2020-12-21 17:51 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-12-21 17:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e798f081925b5085de3c9d0f330eb6e255a377bf

commit r11-6290-ge798f081925b5085de3c9d0f330eb6e255a377bf
Author: Nathan Sidwell <nathan@acm.org>
Date:   Mon Dec 21 09:48:28 2020 -0800

    c++: Windows rename [PR 98412]
    
    Some system's rename(2) fails if the target already exists, so delete it
    first.
    
            gcc/cp/
            * module.cc (create_dirs): Add logging.
            (finish_module_processing): Unlink before rename.

Diff:
---
 gcc/cp/module.cc | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index fc918d296a2..7e38293545f 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -4693,6 +4693,7 @@ create_dirs (char *path)
 	char sep = *base;
 	*base = 0;
 	int failed = mkdir (path, S_IRWXU | S_IRWXG | S_IRWXO);
+	dump () && dump ("Mkdir ('%s') errno:=%u", path, failed ? errno : 0);
 	*base = sep;
 	if (failed
 	    /* Maybe racing with another creator (of a *different*
@@ -19744,8 +19745,17 @@ finish_module_processing (cpp_reader *reader)
 	      input_location = loc;
 	    }
 	  if (to.end ())
-	    if (rename (tmp_name, path))
-	      to.set_error (errno);
+	    {
+	      /* Some OS's do not replace NEWNAME if it already
+		 exists.  This'll have a race condition in erroneous
+		 concurrent builds.  */
+	      unlink (path);
+	      if (rename (tmp_name, path))
+		{
+		  dump () && dump ("Rename ('%s','%s') errno=%u", errno);
+		  to.set_error (errno);
+		}
+	    }
 
 	  if (to.get_error ())
 	    {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-21 17:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 17:51 [gcc r11-6290] c++: Windows rename [PR 98412] Nathan Sidwell

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).