fix(core): handle permission error when checking system host config and patch in tests

This commit is contained in:
Lars committed 2026-10-29 15:31:39 +01:00
1 parent 3c1589bd0c
commit 0bbc4ce440
2 files changed
+22 -12

No files matched your search

+21 -12
View File
@@ -67,9 +67,12 @@ def lock_exclusive(fp):
def resolve_repo_host_dir(host_name=None):
host = host_name or socket.gethostname().split('.')[0]
candidate = Path(__file__).resolve().parent / 'hosts' / host
return candidate if candidate.is_dir() else None
try:
host = host_name or socket.gethostname().split('.')[0]
candidate = Path(__file__).resolve().parent / 'hosts' / host
return candidate if candidate.is_dir() else None
except (OSError, PermissionError):
return None
def load_host_config(path=DEFAULT_HOST_CONFIG, host_name=None):
@@ -95,12 +98,15 @@ def load_host_config(path=DEFAULT_HOST_CONFIG, host_name=None):
if host_dir:
candidates.append(host_dir / 'host.json')
for candidate in candidates:
if candidate.is_file():
with candidate.open(encoding='utf-8') as fp:
data = json.load(fp)
if isinstance(data, dict):
default.update(data)
break
try:
if candidate.is_file():
with candidate.open(encoding='utf-8') as fp:
data = json.load(fp)
if isinstance(data, dict):
default.update(data)
break
except (OSError, PermissionError):
continue
return default
@@ -117,9 +123,12 @@ def load_targets_config(path=DEFAULT_TARGETS_CONFIG, host_name=None):
candidates.append(host_dir / 'targets.json')
candidates.append(Path(__file__).resolve().parent / 'targets.json')
for candidate in candidates:
if candidate.is_file():
with candidate.open(encoding='utf-8') as fp:
return json.load(fp)
try:
if candidate.is_file():
with candidate.open(encoding='utf-8') as fp:
return json.load(fp)
except (OSError, PermissionError):
continue
return {'schemaVersion': 1, 'hosts': {}, 'targets': {}}