mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
parent
0d622f92a9
commit
a924b971ef
1 changed files with 17 additions and 10 deletions
|
@ -2317,6 +2317,7 @@ def detached(name,
|
|||
else:
|
||||
# Clone repository
|
||||
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
|
||||
|
@ -2333,20 +2334,26 @@ def detached(name,
|
|||
'place (force_clone=True set in git.detached state)'
|
||||
.format(target, name)
|
||||
)
|
||||
try:
|
||||
if os.path.islink(target):
|
||||
os.unlink(target)
|
||||
else:
|
||||
salt.utils.rm_rf(target)
|
||||
except OSError as exc:
|
||||
removal_errors = {}
|
||||
for target_object in target_contents:
|
||||
target_path = os.path.join(target, target_object)
|
||||
try:
|
||||
salt.utils.rm_rf(target_path)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.ENOENT:
|
||||
removal_errors[target_path] = exc
|
||||
if removal_errors:
|
||||
err_strings = [
|
||||
' {0}\n {1}'.format(k, v)
|
||||
for k, v in six.iteritems(removal_errors)
|
||||
]
|
||||
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
|
||||
elif os.listdir(target):
|
||||
ret['changes']['forced clone'] = True
|
||||
elif target_contents:
|
||||
# Clone is required, but target dir exists and is non-empty. We
|
||||
# can't proceed.
|
||||
return _fail(
|
||||
|
|
Loading…
Add table
Reference in a new issue