mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Remove directory content instead of directory itself when using force_clone
in git.latest
state. (refs #31363)
This commit is contained in:
parent
e62603d5eb
commit
9ed85f3c59
1 changed files with 14 additions and 9 deletions
|
@ -1589,6 +1589,7 @@ def latest(name,
|
|||
return _uptodate(ret, target, _format_comments(comments))
|
||||
else:
|
||||
if os.path.isdir(target):
|
||||
target_contents = os.listdir(target)
|
||||
if force_clone:
|
||||
# Clone is required, and target directory exists, but the
|
||||
# ``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)'
|
||||
.format(target, name)
|
||||
)
|
||||
try:
|
||||
if os.path.islink(target):
|
||||
os.unlink(target)
|
||||
else:
|
||||
removal_errors = {}
|
||||
for target_object in target_contents:
|
||||
target_path = os.path.join(target, target_object)
|
||||
try:
|
||||
salt.utils.rm_rf(target)
|
||||
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(
|
||||
ret,
|
||||
'Unable to remove {0}: {1}'.format(target, exc),
|
||||
'Unable to remove\n{0}'.format('\n'.join(err_strings)),
|
||||
comments
|
||||
)
|
||||
else:
|
||||
ret['changes']['forced clone'] = True
|
||||
ret['changes']['forced clone'] = True
|
||||
# Clone is required, but target dir exists and is non-empty. We
|
||||
# can't proceed.
|
||||
elif os.listdir(target):
|
||||
elif target_contents:
|
||||
return _fail(
|
||||
ret,
|
||||
'Target \'{0}\' exists, is non-empty and is not a git '
|
||||
|
|
Loading…
Add table
Reference in a new issue