Replaced instances of shutil.rmtree in file state

This commit is contained in:
twangboy 2015-10-21 17:46:37 -06:00
parent 2651ce509f
commit 5ed7a99792

View file

@ -427,7 +427,7 @@ def _clean_dir(root, keep, exclude_pat):
try:
os.remove(nfn)
except OSError:
shutil.rmtree(nfn)
__salt__['file.remove'](nfn)
for roots, dirs, files in os.walk(root):
for name in itertools.chain(dirs, files):
@ -929,10 +929,10 @@ def symlink(
return _error(ret, ((
'File exists where the backup target {0} should go'
).format(backupname)))
elif os.path.isfile(backupname):
os.remove(backupname)
elif os.path.isdir(backupname):
shutil.rmtree(backupname)
elif os.path.isfile(backupname)\
or __salt__['file.is_link'](backupname)\
or os.path.isdir(backupname):
__salt__['file.remove'](backupname)
else:
return _error(ret, ((
'Something exists where the backup target {0}'
@ -941,11 +941,11 @@ def symlink(
os.rename(name, backupname)
elif force:
# Remove whatever is in the way
if os.path.isfile(name):
os.remove(name)
if __salt__['file.is_link'](name):
__salt__['file.remove'](name)
ret['changes']['forced'] = 'Symlink was forcibly replaced'
else:
shutil.rmtree(name)
__salt__['file.remove'](name)
else:
# Otherwise throw an error
if os.path.isfile(name):
@ -1021,7 +1021,7 @@ def absent(name):
ret['comment'] = 'Directory {0} is set for removal'.format(name)
return ret
try:
shutil.rmtree(name)
__salt__['file.remove'](name)
ret['comment'] = 'Removed directory {0}'.format(name)
ret['changes']['removed'] = name
return ret
@ -1781,12 +1781,12 @@ def directory(name,
return _error(ret, ((
'File exists where the backup target {0} should go'
).format(backupname)))
elif os.path.isfile(backupname):
os.remove(backupname)
elif os.path.islink(backupname):
os.remove(backupname)
elif os.path.isdir(backupname):
shutil.rmtree(backupname)
elif os.path.isfile(backupname) \
or __salt__['file.is_link'](backupname) \
or os.path.isdir(backupname):
__salt__['file.remove'](backupname)
else:
return _error(ret, ((
'Something exists where the backup target {0}'
@ -1798,11 +1798,11 @@ def directory(name,
if os.path.isfile(name):
os.remove(name)
ret['changes']['forced'] = 'File was forcibly replaced'
elif os.path.islink(name):
os.remove(name)
elif __salt__['file.is_link'](name):
__salt__['file.remove'](name)
ret['changes']['forced'] = 'Symlink was forcibly replaced'
else:
shutil.rmtree(name)
__salt__['file.remove'](name)
else:
if os.path.isfile(name):
return _error(
@ -2227,7 +2227,7 @@ def recurse(name,
merge_ret(path, _ret)
return
else:
shutil.rmtree(path)
__salt__['file.remove'](path)
_ret['changes'] = {'diff': 'Replaced directory with a '
'new file'}
merge_ret(path, _ret)
@ -3646,12 +3646,7 @@ def copy(
elif not __opts__['test'] and changed:
# Remove the destination to prevent problems later
try:
if os.path.islink(name):
os.unlink(name)
elif os.path.isfile(name):
os.remove(name)
else:
shutil.rmtree(name)
__salt__['file.remove'](name)
except (IOError, OSError):
return _error(
ret,
@ -3751,12 +3746,7 @@ def rename(name, source, force=False, makedirs=False):
elif not __opts__['test']:
# Remove the destination to prevent problems later
try:
if os.path.islink(name):
os.unlink(name)
elif os.path.isfile(name):
os.remove(name)
else:
shutil.rmtree(name)
__salt__['file.remove'](name)
except (IOError, OSError):
return _error(
ret,