From a05905e41dd4486669858ea913f48803e1bc5614 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 21 Jun 2018 12:52:20 +0100 Subject: [sosreport] handle OSError in XmlReport.report() The XmlReport class in sos.sosreport traverses the list of plugins and prepares a report including each collected file. The access to the file is wrapped in an except block but the recent change to pycodestyle modified this from a 'naked' except into a 'except IOError' block. Attempting to open a non-existent path yields an IOError, however attempting to stat a non-existent path (or a dangling symlink without lstat()) yields OSError: # ln -s foo qux # cat qux cat: qux: No such file or directory >>> os.stat("/foo/qux") Traceback (most recent call last): File "", line 1, in OSError: [Errno 2] No such file or directory: '/foo/qux' Catch both exception classes in this method. Signed-off-by: Bryn M. Reeves --- sos/sosreport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sos/sosreport.py b/sos/sosreport.py index f47918fe..b37989b0 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -1131,7 +1131,7 @@ class SoSReport(object): try: self.xml_report.add_file(oneFile["srcpath"], os.stat(oneFile["srcpath"])) - except IOError: + except (OSError, IOError): pass try: self.xml_report.serialize_to_file(os.path.join(self.rptdir, -- cgit