[gcc r17-3427] PR modula2/126911: Tidyup removing files

Gaius Mulley via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:e8de2a38c2c9bce2e1b8f94c5f263da57fefba79

commit r17-3427-ge8de2a38c2c9bce2e1b8f94c5f263da57fefba79
Author: Gaius Mulley <[email protected]>
Date:   Wed Aug 19 15:14:22 2026 +0100

    PR modula2/126911: Tidyup removing files
    
    This tiny patch tidies up the removal of a file using
    a function testing for the name being not None and that it exists.
    Boostrapped on Debian x86_64.
    
    gcc/m2/ChangeLog:
    
            PR modula2/126911
            * tools-src/mktargetsrc.py (safeRemove): New function.
            (quietSystem): Call safeRemove for temporaryFile and
            args.outputfile.
    
    Signed-off-by: Gaius Mulley <[email protected]>

Diff:
---
 gcc/m2/tools-src/mktargetsrc.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/tools-src/mktargetsrc.py b/gcc/m2/tools-src/mktargetsrc.py
index 34c19233043e..b91ee7a299b8 100644
--- a/gcc/m2/tools-src/mktargetsrc.py
+++ b/gcc/m2/tools-src/mktargetsrc.py
@@ -38,6 +38,12 @@ def printf (format, *args):
     print(str(format) % args, end=' ')
 
 
+def safeRemove(filename):
+    # Remove filename if the name is not None and the filename exists.
+    if (filename != None) and os.path.exists(filename):
+        os.remove(filename)
+
+
 def quietSystem(args, commandLine, temporaryFile):
     # Execute commandline and exit if unsuccessful.  It will run
     # gdb on the command line if --gdb is set in args.
@@ -46,9 +52,8 @@ def quietSystem(args, commandLine, temporaryFile):
     else:
         result = os.system(commandLine + " 2>&1 /dev/null")
     if result != 0:
-        os.remove(temporaryFile)
-        if (args.outputfile != None) and os.path.exists(args.outputfile):
-            os.remove(args.outputfile)
+        safeRemove(temporaryFile)
+        safeRemove(args.outputfile)
         printf("failed to execute: %s with an exit code: %d\n",
                commandLine, result)
         sys.exit(result)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.