[OE-core] [OE-Core][PATCH] lib/oe/qa: handle missing data attribute in __exit__
Alex Kiernan
alex.kiernan at gmail.com
Sun Dec 29 09:31:46 UTC 2019
If mmap fails in open, we don't have a data attribute so when we execute
as a context manager the call to self.data.close needs to handle the
missing attribute:
File: '/home/akiernan/nanohub/build/../poky/meta/classes/chrpath.bbclass', lineno: 11, function: process_file_linux
0007: with oe.qa.ELFFile(fpath) as elf:
0008: try:
0009: elf.open()
0010: except oe.qa.NotELFFileError:
*** 0011: return
0012:
0013: p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
0014: out, err = p.communicate()
0015: # If returned successfully, process stdout for results
File: '/home/akiernan/nanohub/build/../poky/meta/lib/oe/qa.py', lineno: 50, function: __exit__
0046: def __enter__(self):
0047: return self
0048:
0049: def __exit__(self, exc_type, exc_value, traceback):
*** 0050: self.data.close()
0051:
0052: def open(self):
0053: with open(self.name, "rb") as f:
0054: try:
Exception: AttributeError: 'ELFFile' object has no attribute 'data'
Fixes: 7785c41d0b95 ("chrpath: do less work")
Signed-off-by: Alex Kiernan <alex.kiernan at gmail.com>
---
meta/lib/oe/qa.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/meta/lib/oe/qa.py b/meta/lib/oe/qa.py
index 21066c4dc3b3..d85206f155f0 100644
--- a/meta/lib/oe/qa.py
+++ b/meta/lib/oe/qa.py
@@ -47,7 +47,11 @@ class ELFFile:
return self
def __exit__(self, exc_type, exc_value, traceback):
- self.data.close()
+ try:
+ self.data.close()
+ except AttributeError:
+ # If we failed to mmap in open then the data attribute won't exist
+ pass
def open(self):
with open(self.name, "rb") as f:
--
2.17.1
More information about the Openembedded-core
mailing list