decodetree: Do not remove output_file from /dev
authorRichard Henderson <richard.henderson@linaro.org>
Fri, 26 May 2023 17:22:51 +0000 (10:22 -0700)
committerRichard Henderson <richard.henderson@linaro.org>
Tue, 30 May 2023 17:55:39 +0000 (10:55 -0700)
Nor report any PermissionError on remove.
The primary purpose is testing with -o /dev/null.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
scripts/decodetree.py

index e4ef0a03cc4c7ee9f1a5f372f1f83f112d8ae4a4..a9a0cd0fa3a75cbe24ae1647405795f7158cde85 100644 (file)
@@ -71,7 +71,12 @@ def error_with_file(file, lineno, *args):
 
     if output_file and output_fd:
         output_fd.close()
-        os.remove(output_file)
+        # Do not try to remove e.g. -o /dev/null
+        if not output_file.startswith("/dev"):
+            try:
+                os.remove(output_file)
+            except PermissionError:
+                pass
     exit(0 if testforerror else 1)
 # end error_with_file