From 7709298a2b5ab0eb3a2990bb2fd4ead7d1b29674 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 18 Sep 2020 13:18:06 +0200 Subject: [PATCH] edd: Fix UnboundLocalError when trying to close fd in collect_mbrs The "fd" variable is not defined when the "os.open" fails (e.g. when the device we try to open doesn't exist). Conflict:NA Reference:https://github.com/storaged-project/blivet/commit/7709298a2b5ab0eb3a2990bb2fd4ead7d1b29674 --- blivet/devicelibs/edd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blivet/devicelibs/edd.py b/blivet/devicelibs/edd.py index f64c4e5..67b7186 100644 --- a/blivet/devicelibs/edd.py +++ b/blivet/devicelibs/edd.py @@ -664,6 +664,7 @@ def collect_mbrs(devices, root=None): """ mbr_dict = {} for dev in devices: + fd = -1 try: path = util.Path("/dev", root=root) + dev.name fd = os.open(path.ondisk, os.O_RDONLY) @@ -679,7 +680,7 @@ def collect_mbrs(devices, root=None): testdata_log.debug("device %s data[440:443] raised %s", path, e) log.error("edd: could not read mbrsig from disk %s: %s", dev.name, str(e)) - if fd: + if fd > 0: os.close(fd) continue -- 2.23.0