Raise CommandExecutionError when file doesn't exist

Re-add CommandExecutionError in win_file
Add CommandExecutionError in file
Add Try/Except block in file when getting file metadata
This commit is contained in:
twangboy 2017-09-11 11:23:28 -06:00
parent 4602f499a2
commit e3c3845f73
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB
2 changed files with 11 additions and 4 deletions

View file

@ -3368,7 +3368,7 @@ def stats(path, hash_type=None, follow_symlinks=True):
pstat = os.lstat(path)
except OSError:
# Not a broken symlink, just a nonexistent path
return ret
raise CommandExecutionError('Path not found: {0}'.format(path))
else:
if follow_symlinks:
pstat = os.stat(path)
@ -4498,11 +4498,18 @@ def check_file_meta(
'''
changes = {}
if not source_sum:
source_sum = {}
lstats = stats(name, hash_type=source_sum.get('hash_type', None), follow_symlinks=False)
source_sum = dict()
try:
lstats = stats(name, hash_type=source_sum.get('hash_type', None),
follow_symlinks=False)
except CommandExecutionError:
lstats = {}
if not lstats:
changes['newfile'] = name
return changes
if 'hsum' in source_sum:
if source_sum['hsum'] != lstats['sum']:
if not sfn and source:

View file

@ -821,7 +821,7 @@ def stats(path, hash_type='sha256', follow_symlinks=True):
# This is to mirror the behavior of file.py. `check_file_meta` expects an
# empty dictionary when the file does not exist
if not os.path.exists(path):
return {}
raise CommandExecutionError('Path not found: {0}'.format(path))
if follow_symlinks and sys.getwindowsversion().major >= 6:
path = _resolve_symlink(path)