mirror of
https://github.com/Kozea/Radicale.git
synced 2025-07-23 17:48:30 +00:00
config & rights: use open() for better error messages
ConfigParser().read() doesn't differentiate between different types of failure to read files, causing eg. "No such file" to be logged in all cases, for example if permissions are insufficient. fix that by using open() and ConfigParser().read_file() instead.
This commit is contained in:
parent
63619e1ef7
commit
035ff2b546
2 changed files with 10 additions and 9 deletions
|
@ -276,17 +276,18 @@ def load(paths: Optional[Iterable[Tuple[str, bool]]] = None
|
|||
for path, ignore_if_missing in paths:
|
||||
parser = RawConfigParser()
|
||||
config_source = "config file %r" % path
|
||||
config: types.CONFIG
|
||||
try:
|
||||
if not parser.read(path):
|
||||
config = Configuration.SOURCE_MISSING
|
||||
if not ignore_if_missing:
|
||||
raise RuntimeError("No such file: %r" % path)
|
||||
else:
|
||||
with open(path, "r") as f:
|
||||
parser.read_file(f)
|
||||
config = {s: {o: parser[s][o] for o in parser.options(s)}
|
||||
for s in parser.sections()}
|
||||
except Exception as e:
|
||||
raise RuntimeError("Failed to load %s: %s" % (config_source, e)
|
||||
) from e
|
||||
if isinstance(e, FileNotFoundError) and ignore_if_missing:
|
||||
config = Configuration.SOURCE_MISSING
|
||||
else:
|
||||
raise RuntimeError("Failed to load %s: %s" % (config_source, e)
|
||||
) from e
|
||||
configuration.update(config, config_source)
|
||||
return configuration
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue