aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2017-11-09 19:45:15 -0500
committerElliott Sales de Andrade <quantum.analyst@gmail.com>2017-11-09 19:45:28 -0500
commit5f8b37d0e7a20c64dee066d7fa1bee12803a1626 (patch)
tree8cd65ef18bfee3ee7103997516f9c48dfc370cb9
parent34d928a83011005bf44df26b4b32c3777b2e6595 (diff)
downloadmeson-5f8b37d0e7a20c64dee066d7fa1bee12803a1626.zip
meson-5f8b37d0e7a20c64dee066d7fa1bee12803a1626.tar.gz
meson-5f8b37d0e7a20c64dee066d7fa1bee12803a1626.tar.bz2
Coalesce restorecon calls into one.
Fixes #2596.
-rw-r--r--mesonbuild/scripts/meson_install.py28
1 files changed, 12 insertions, 16 deletions
diff --git a/mesonbuild/scripts/meson_install.py b/mesonbuild/scripts/meson_install.py
index 985b0e9..b0a7d19 100644
--- a/mesonbuild/scripts/meson_install.py
+++ b/mesonbuild/scripts/meson_install.py
@@ -20,7 +20,7 @@ from . import destdir_join
from ..mesonlib import is_windows, Popen_safe
install_log_file = None
-use_selinux = True
+selinux_updates = []
class DirMaker:
def __init__(self):
@@ -84,27 +84,22 @@ def set_mode(path, mode):
msg = '{!r}: Unable to set permissions {!r}: {}, ignoring...'
print(msg.format(path, mode.perms_s, e.strerror))
-def restore_selinux_context(to_file):
+def restore_selinux_contexts():
'''
- Restores the SELinux context for @to_file
+ Restores the SELinux context for files in @selinux_updates
'''
- global use_selinux
-
- if not use_selinux:
- return
-
try:
subprocess.check_call(['selinuxenabled'])
- try:
- subprocess.check_call(['restorecon', '-F', to_file], stderr=subprocess.DEVNULL)
- except subprocess.CalledProcessError as e:
- use_selinux = False
- msg = "{!r}: Failed to restore SELinux context, ignoring SELinux context for all remaining files..."
- print(msg.format(to_file, e.returncode))
except (FileNotFoundError, PermissionError, subprocess.CalledProcessError) as e:
# If we don't have selinux or selinuxenabled returned 1, failure
# is ignored quietly.
- use_selinux = False
+ return
+
+ try:
+ subprocess.check_call(['restorecon', '-F'] + selinux_updates, stderr=subprocess.DEVNULL)
+ except subprocess.CalledProcessError as e:
+ msg = "{!r}: Failed to restore SELinux context, ignoring SELinux context for all remaining files..."
+ print(msg.format(selinux_updates, e.returncode))
def append_to_log(line):
install_log_file.write(line)
@@ -126,7 +121,7 @@ def do_copyfile(from_file, to_file):
os.unlink(to_file)
shutil.copyfile(from_file, to_file)
shutil.copystat(from_file, to_file)
- restore_selinux_context(to_file)
+ selinux_updates.append(to_file)
append_to_log(to_file)
def do_copydir(data, src_prefix, src_dir, dst_dir, exclude):
@@ -192,6 +187,7 @@ def do_install(datafilename):
install_headers(d)
install_man(d)
install_data(d)
+ restore_selinux_contexts()
run_install_script(d)
def install_subdirs(d):