[binutils-gdb] gdb/testsuite: Use file_rename_atomic in gdb_do_cache too

Pedro Alves via Gdb-cvs <[email protected]> Wed, 22 Jul 2026 16:10:03 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D01283ef6e040=
d30a026721eb1ff9e8d9e7345039

commit 01283ef6e040d30a026721eb1ff9e8d9e7345039
Author: Pedro Alves <[email protected]>
Date:   Wed Jul 22 16:08:55 2026 +0100

    gdb/testsuite: Use file_rename_atomic in gdb_do_cache too
   =20
    An earlier commit ("Windows: Fix set_unbuffered_mode.o file rename
    race") introduced file_rename_atomic to ignore EBUSY when multiple
    parallel workers race to rename their identical copy of a file to a
    shared final destination, and converted the two atomic renames in
    gdb.exp to use it.
   =20
    gdb_do_cache in cache.exp does the same thing: in GDB_PARALLEL mode,
    each worker writes the results cache to a per-pid temporary file and
    then atomically renames it into place, so it can hit the same EBUSY
    race on Windows.  It was missed by that commit.
   =20
    Fix it by using file_rename_atomic there too.
   =20
    Approved-By: Tom Tromey <[email protected]>
    Change-Id: I9780ed4989f9c4e9daf7143280cd63a65c6918ed

Diff:
---
 gdb/testsuite/lib/cache.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/testsuite/lib/cache.exp b/gdb/testsuite/lib/cache.exp
index 1ba8c881716..1e2d470773a 100644
--- a/gdb/testsuite/lib/cache.exp
+++ b/gdb/testsuite/lib/cache.exp
@@ -262,7 +262,7 @@ proc gdb_do_cache {name args} {
 	puts $fd $gdb_data_cache(${cache_name},exit)
 	puts $fd $gdb_data_cache(${cache_name},also_called)
 	close $fd
-	file rename -force -- $cache_filename.[pid] $cache_filename
+	file_rename_atomic $cache_filename.[pid] $cache_filename
     }
     gdb_cache_maybe_gdb_exit $name $gdb_data_cache(${cache_name},exit) \
 	$gdb_data_cache(${cache_name},also_called)