qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] decodetree: Do not remove output_file from /dev
@ 2023-05-26 17:40 Richard Henderson
  2023-05-26 19:52 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2023-05-26 17:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

Nor report any PermissionError on remove.

Previously we were testing with "> /dev/null", but that's not easy
to do with meson test(), so we want to use '-o /dev/null' instead.
That works fine for all of the existing tests, where all errors are
diagnosed before opening the output file.  However, PMM's named field
patch set diagnoses cycle errors during output.  This is fair, but
we need to be more careful with the remove.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 scripts/decodetree.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index e4ef0a03cc..a9a0cd0fa3 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -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
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] decodetree: Do not remove output_file from /dev
  2023-05-26 17:40 [PATCH] decodetree: Do not remove output_file from /dev Richard Henderson
@ 2023-05-26 19:52 ` Peter Maydell
  2023-05-26 21:49   ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2023-05-26 19:52 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Fri, 26 May 2023 at 18:40, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Nor report any PermissionError on remove.
>
> Previously we were testing with "> /dev/null", but that's not easy
> to do with meson test(), so we want to use '-o /dev/null' instead.
> That works fine for all of the existing tests, where all errors are
> diagnosed before opening the output file.  However, PMM's named field
> patch set diagnoses cycle errors during output.  This is fair, but
> we need to be more careful with the remove.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  scripts/decodetree.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/decodetree.py b/scripts/decodetree.py
> index e4ef0a03cc..a9a0cd0fa3 100644
> --- a/scripts/decodetree.py
> +++ b/scripts/decodetree.py
> @@ -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

Maybe rather than hardcoding /dev, only try to delete the file
if it's a normal file, i.e.:
       if os.path.isfile(output_file):
           os.remove(output_file)

?

-- PMM


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] decodetree: Do not remove output_file from /dev
  2023-05-26 19:52 ` Peter Maydell
@ 2023-05-26 21:49   ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2023-05-26 21:49 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 5/26/23 12:52, Peter Maydell wrote:
> On Fri, 26 May 2023 at 18:40, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Nor report any PermissionError on remove.
>>
>> Previously we were testing with "> /dev/null", but that's not easy
>> to do with meson test(), so we want to use '-o /dev/null' instead.
>> That works fine for all of the existing tests, where all errors are
>> diagnosed before opening the output file.  However, PMM's named field
>> patch set diagnoses cycle errors during output.  This is fair, but
>> we need to be more careful with the remove.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   scripts/decodetree.py | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/decodetree.py b/scripts/decodetree.py
>> index e4ef0a03cc..a9a0cd0fa3 100644
>> --- a/scripts/decodetree.py
>> +++ b/scripts/decodetree.py
>> @@ -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
> 
> Maybe rather than hardcoding /dev, only try to delete the file
> if it's a normal file, i.e.:
>         if os.path.isfile(output_file):
>             os.remove(output_file)

Good idea.


r~



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-26 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26 17:40 [PATCH] decodetree: Do not remove output_file from /dev Richard Henderson
2023-05-26 19:52 ` Peter Maydell
2023-05-26 21:49   ` Richard Henderson

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 NNTP newsgroup(s).