From 7e8d5207a7c662beeae41b375e0af5c96f57e7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 7 Jun 2021 10:42:18 +0200 Subject: install: update restore_selinux to use popen_safe Use Popen_safe to simplify the code. --- mesonbuild/minstall.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index 654b547..2a4f68a 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -229,6 +229,9 @@ def restore_selinux_contexts() -> None: # is ignored quietly. return + if os.environ.get('DESTDIR'): + return + if not shutil.which('restorecon'): # If we don't have restorecon, failure is ignored quietly. return @@ -237,13 +240,11 @@ def restore_selinux_contexts() -> None: # If the list of files is empty, do not try to call restorecon. return - with subprocess.Popen(['restorecon', '-F', '-f-', '-0'], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: - out, err = proc.communicate(input=b'\0'.join(os.fsencode(f) for f in selinux_updates) + b'\0') - if proc.returncode != 0 and not os.environ.get('DESTDIR'): - print('Failed to restore SELinux context of installed files...', - 'Standard output:', out.decode(), - 'Standard error:', err.decode(), sep='\n') + proc, out, err = Popen_safe(['restorecon', '-F', '-f-', '-0'], (b'\0'.join(os.fsencode(f) for f in selinux_updates) + b'\0').decode()) + if proc.returncode != 0 : + print('Failed to restore SELinux context of installed files...', + 'Standard output:', out, + 'Standard error:', err, sep='\n') def get_destdir_path(destdir: str, fullprefix: str, path: str) -> str: -- cgit v1.1