Check the existence of the file before trying to read from it

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-08-23 21:26:27 +01:00 committed by Pedro Algarvio
parent c2a15672ba
commit aa34a59dad

View file

@ -591,8 +591,10 @@ def sync_cache(
cached_instances = {}
if STATE_DIR.exists():
for state_path in STATE_DIR.iterdir():
instance_id = (state_path / "instance-id").read_text()
cached_instances[instance_id] = state_path.name
instance_id_path = state_path / "instance-id"
if instance_id_path.exists():
instance_id = instance_id_path.read_text()
cached_instances[instance_id] = state_path.name
# Find what instances we are missing in our cached states
to_write = {}