2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-29 13:28:19 +00:00

utils: skip user config reading in aa-notify when --configdir is given

--configdir is meant for testing and should override all other configs,
instead of being combined with them. Config combination causes aa-notify
test failures if e.g. the user-local config sets filtering options.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
This commit is contained in:
Ryan Lee 2025-04-03 12:17:25 -07:00
parent 3b3dada5d9
commit 096c8df52b

View File

@ -891,19 +891,22 @@ def main():
if not system_config: if not system_config:
system_config = {'': {'show_notifications': 'yes'}} system_config = {'': {'show_notifications': 'yes'}}
# Load user's notify.conf # Load user's notify.conf if a configdir override was not specified
if os.path.isfile(os.environ['HOME'] + '/.apparmor/notify.conf'): if not args.configdir:
# Use legacy path if the conf file is there if os.path.isfile(os.environ['HOME'] + '/.apparmor/notify.conf'):
user_config = read_notify_conf(os.environ['HOME'] + '/.apparmor', shell_config) # Use legacy path if the conf file is there
elif 'XDG_CONFIG_HOME' in os.environ and os.path.isfile(os.environ['XDG_CONFIG_HOME'] + '/apparmor/notify.conf'): user_config = read_notify_conf(os.environ['HOME'] + '/.apparmor', shell_config)
# Use XDG_CONFIG_HOME if it is defined elif 'XDG_CONFIG_HOME' in os.environ and os.path.isfile(os.environ['XDG_CONFIG_HOME'] + '/apparmor/notify.conf'):
user_config = read_notify_conf(os.environ['XDG_CONFIG_HOME'] + '/apparmor', shell_config) # Use XDG_CONFIG_HOME if it is defined
else: user_config = read_notify_conf(os.environ['XDG_CONFIG_HOME'] + '/apparmor', shell_config)
# Fallback to the default value of XDG_CONFIG_HOME else:
user_config = read_notify_conf(os.environ['HOME'] + '/.config/apparmor', shell_config) # Fallback to the default value of XDG_CONFIG_HOME
user_config = read_notify_conf(os.environ['HOME'] + '/.config/apparmor', shell_config)
# Merge the two config dicts in an accurate and idiomatic way (requires Python 3.5) # Merge the two config dicts in an accurate and idiomatic way (requires Python 3.5)
config = {**system_config, **user_config} config = {**system_config, **user_config}
else:
config = system_config
""" """
Possible configuration options: Possible configuration options: