diff --git a/salt/utils/files.py b/salt/utils/files.py index 65b4783c03..ec223c1685 100644 --- a/salt/utils/files.py +++ b/salt/utils/files.py @@ -205,10 +205,22 @@ def rename(src, dst): os.rename(src, dst) -def process_read_exception(exc, path): +def process_read_exception(exc, path, ignore=None): ''' Common code for raising exceptions when reading a file fails + + The ignore argument can be an iterable of integer error codes (or a single + integer error code) that should be ignored. ''' + if ignore is not None: + if isinstance(ignore, six.integer_types): + ignore = (ignore,) + else: + ignore = () + + if exc.errno in ignore: + return + if exc.errno == errno.ENOENT: raise CommandExecutionError('{0} does not exist'.format(path)) elif exc.errno == errno.EACCES: