Merge branch 'fix-31363' of https://github.com/zer0def/salt into zer0def-fix-31363

This commit is contained in:
Erik Johnson 2017-04-05 21:20:10 -05:00
commit 7f3cbd5cf9

View File

@ -1589,6 +1589,7 @@ def latest(name,
return _uptodate(ret, target, _format_comments(comments)) return _uptodate(ret, target, _format_comments(comments))
else: else:
if os.path.isdir(target): if os.path.isdir(target):
target_contents = os.listdir(target)
if force_clone: if force_clone:
# Clone is required, and target directory exists, but the # Clone is required, and target directory exists, but the
# ``force`` option is enabled, so we need to clear out its # ``force`` option is enabled, so we need to clear out its
@ -1607,22 +1608,26 @@ def latest(name,
'place (force_clone=True set in git.latest state)' 'place (force_clone=True set in git.latest state)'
.format(target, name) .format(target, name)
) )
try: removal_errors = {}
if os.path.islink(target): for target_object in target_contents:
os.unlink(target) target_path = os.path.join(target, target_object)
else: try:
salt.utils.rm_rf(target) salt.utils.rm_rf(target_path)
except OSError as exc: except OSError as exc:
removal_errors[target_path] = exc
if removal_errors:
err_strings = [
' {0}\n {1}'.format(k, v) for k, v in removal_errors.items()
]
return _fail( return _fail(
ret, ret,
'Unable to remove {0}: {1}'.format(target, exc), 'Unable to remove\n{0}'.format('\n'.join(err_strings)),
comments comments
) )
else: ret['changes']['forced clone'] = True
ret['changes']['forced clone'] = True
# Clone is required, but target dir exists and is non-empty. We # Clone is required, but target dir exists and is non-empty. We
# can't proceed. # can't proceed.
elif os.listdir(target): elif target_contents:
return _fail( return _fail(
ret, ret,
'Target \'{0}\' exists, is non-empty and is not a git ' 'Target \'{0}\' exists, is non-empty and is not a git '