Add ignore ability to process_read_exception

This commit is contained in:
Erik Johnson 2018-11-27 11:45:01 -06:00
parent 015834ded9
commit 9f547205a0
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -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: