From 5cf0e7a830cce8988e0def4714f21be2426bfdeb Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 7 Apr 2014 20:29:09 +0100 Subject: [PATCH 03/17] Improve error reporting on mkdir failure Signed-off-by: Bryn M. Reeves --- sos/policyredhat.py | 4 +++- sos/sosreport.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sos/policyredhat.py b/sos/policyredhat.py index 7e6b2c1..0535a18 100755 --- a/sos/policyredhat.py +++ b/sos/policyredhat.py @@ -203,7 +203,9 @@ class SosPolicy: dstroot = os.path.join(os.path.abspath(tmpdir),uniqname) try: os.makedirs(dstroot, 0700) - except: + except Exception as e: + print "Failed to create temporary directory:" + print e return False return dstroot diff --git a/sos/sosreport.py b/sos/sosreport.py index d24cf3f..862476c 100755 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -353,15 +353,21 @@ def sosreport(opts): GlobalVars.dstroot = GlobalVars.policy.getDstroot(GlobalVars.__cmdLineOpts__.tmp_dir) if not GlobalVars.dstroot: - print _("Could not create temporary directory.") - doExit() + print _("Aborting.") + doExit(1) cmddir = os.path.join(GlobalVars.dstroot, "sos_commands") logdir = os.path.join(GlobalVars.dstroot, "sos_logs") rptdir = os.path.join(GlobalVars.dstroot, "sos_reports") - os.mkdir(cmddir, 0755) - os.mkdir(logdir, 0755) - os.mkdir(rptdir, 0755) + try: + os.mkdir(cmddir, 0755) + os.mkdir(logdir, 0755) + os.mkdir(rptdir, 0755) + except Exception as e: + print _("Failed to create temporary directory:") + print e + print _("Aborting.") + doExit(1) # initialize logging soslog = logging.getLogger('sos') -- 1.9.3