From 46464390f902ee2e40f348d847d59aff6fc267e5 Mon Sep 17 00:00:00 2001 From: ma Date: Tue, 13 Feb 2024 16:57:10 +0100 Subject: [PATCH] #12: catch file not found error and log warning --- libqmpbackup/image.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libqmpbackup/image.py b/libqmpbackup/image.py index 0fc79fd..0bef853 100644 --- a/libqmpbackup/image.py +++ b/libqmpbackup/image.py @@ -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: