From 2d779a14e4fe438fedeca0cfc3d0f73d23ead9a6 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 13 Feb 2024 17:24:24 +0100 Subject: [PATCH] util: fall back to /usr/share for storage.conf if no /etc config The system-wide location for the containers storage.conf is /usr/share/containers. The existence of a file in /etc/containers completely overrides this (see containers-storage.conf(5)). If no file is found at /etc/containers/storage.conf then fall back to reading the config from /usr/share/containers/storage.conf. If neither file exists, this is an error since the default config should be packaged with any tool that requires it (skopeo, podman, etc). --- osbuild/util/containers.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/osbuild/util/containers.py b/osbuild/util/containers.py index 1a1a3982..2a40b550 100644 --- a/osbuild/util/containers.py +++ b/osbuild/util/containers.py @@ -182,7 +182,14 @@ def get_host_storage(storage_conf=None): except ImportError: import tomli as toml + config_paths = ("/etc/containers/storage.conf", "/usr/share/containers/storage.conf") if not storage_conf: - with open("/etc/containers/storage.conf", "rb") as conf_file: - storage_conf = toml.load(conf_file) - return storage_conf + for conf_path in config_paths: + try: + with open(conf_path, "rb") as conf_file: + storage_conf = toml.load(conf_file) + return storage_conf + except FileNotFoundError: + pass + + raise FileNotFoundError(f"could not find container storage configuration in any of {config_paths}")