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).
This commit is contained in:
parent
06801bb442
commit
2d779a14e4
1 changed files with 10 additions and 3 deletions
|
|
@ -182,7 +182,14 @@ def get_host_storage(storage_conf=None):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import tomli as toml
|
import tomli as toml
|
||||||
|
|
||||||
|
config_paths = ("/etc/containers/storage.conf", "/usr/share/containers/storage.conf")
|
||||||
if not storage_conf:
|
if not storage_conf:
|
||||||
with open("/etc/containers/storage.conf", "rb") as conf_file:
|
for conf_path in config_paths:
|
||||||
storage_conf = toml.load(conf_file)
|
try:
|
||||||
return storage_conf
|
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}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue