diff --git a/stapled/core/certfinder.py b/stapled/core/certfinder.py index 474716d..842bf45 100644 --- a/stapled/core/certfinder.py +++ b/stapled/core/certfinder.py @@ -28,6 +28,7 @@ import fnmatch import os import stapled +import errno from stapled.core.excepthandler import stapled_except_handle from stapled.core.taskcontext import StapleTaskContext from stapled.core.certmodel import CertModel @@ -165,13 +166,15 @@ def _find_new_certs(self, paths, cert_path=None): dirs = [] try: dirs = os.listdir(path) - except NotADirectoryError: + except (OSError, IOError) as exc: # If a path is actually a file we can still use it.. - if os.path.isfile(path): + if exc.errno == errno.ENOTDIR and os.path.isfile(path): LOG.debug("%s may be a single file", path) # This will allow us to use our usual iteration. dirs = [os.path.basename(path)] path = os.path.dirname(path) + else: + raise exc for entry in dirs: entry = os.path.join(path, entry) if os.path.isdir(entry): diff --git a/stapled/core/excepthandler.py b/stapled/core/excepthandler.py index 47b4269..0120fe6 100755 --- a/stapled/core/excepthandler.py +++ b/stapled/core/excepthandler.py @@ -35,6 +35,7 @@ import datetime import logging import os +import errno import traceback import configargparse from stapled.core.exceptions import OCSPBadResponse @@ -150,8 +151,17 @@ def stapled_except_handle(ctx=None): "entries", err_count, len_ocsp_urls ) - except PermissionError as exc: - LOG.critical(exc) + except (IOError, OSError) as exc: + if exc.errno==errno.EPERM or exc.errno==errno.EACCES: + reason = "Permission error" + elif exc.errno==errno.ENOENT: + reason = "File not found error" + elif isinstance(exc, IOError): + reason = "I/O Error" + else: + reason = "OS Error" + + LOG.critical("{}: {}".format(reason, str(exc))) # the show must go on.. except Exception as exc: # pylint: disable=broad-except