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]>
---
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 34c19233043..b91ee7a299b 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)
--
2.47.3