Avoid to crash on unicode decoding errors

As kobo.shortcuts.run can't handle binary output correctly, it causes
pungi-make-ostree crashed when rpm-ostree outputs unexpected characters.

JIRA: RHELCMP-14253
Fixes: https://pagure.io/releng/issue/12474
Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2024-12-11 13:49:16 +08:00
parent b058f64abe
commit 7d8f3b4b9b
2 changed files with 88 additions and 42 deletions

View file

@ -16,6 +16,7 @@
import os
import json
import subprocess
from kobo import shortcuts
from pungi.util import makedirs
@ -59,13 +60,19 @@ class Tree(OSTree):
# permissions. See https://pagure.io/releng/issue/8811#comment-629051
oldumask = os.umask(0o0002)
try:
shortcuts.run(
cmd,
show_cmd=True,
stdout=True,
logfile=log_file,
universal_newlines=True,
)
with open(log_file, "w") as f:
f.write(f"COMMAND: {' '.join(cmd)}\n")
f.flush()
proc = subprocess.Popen(
cmd,
shell=True,
stdout=f,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
ret_code = proc.wait()
if ret_code:
raise RuntimeError(f"Failed to run rpm-ostree, log_file: {log_file}")
finally:
os.umask(oldumask)