Skip to content

Commit

Permalink
#12: catch file not found error and log warning
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Feb 13, 2024
1 parent b7984fb commit 4646439
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libqmpbackup/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ def save_info(backupdir, blockdev):
"""Save qcow image information"""
for dev in blockdev:
infofile = f"{backupdir}/{dev.node}.config"

if not os.path.exists(dev.filename):
log.warning(
"Unable to save image file info: not existent: skipping: [%s]",
dev.filename,
)
continue

info = get_info(dev.filename)
try:
with open(infofile, "wb+") as info_file:
info_file.write(info)
log.info("Saved image info: [%s]", infofile)
except FileNotFoundError:
log.warning("Unable to query image config from file: [%s]", dev.filename)
except IOError as errmsg:
raise RuntimeError(f"Unable to store qcow config: [{errmsg}]") from errmsg
except Exception as errmsg:
Expand Down

0 comments on commit 4646439

Please sign in to comment.