Skip to content

Commit

Permalink
Merge pull request #51740 from arizvisa/GH-51739
Browse files Browse the repository at this point in the history
Updated the salt.states.file.copy function to make the call to file.remove with the force parameter set to the same as one for salt.states.file.copy.
  • Loading branch information
dwoz authored Mar 7, 2019
2 parents 522c7a1 + 1247621 commit 19a1882
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion salt/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3787,7 +3787,7 @@ def rmdir(path):
return exc.strerror


def remove(path):
def remove(path, **kwargs):
'''
Remove the named file. If a directory is supplied, it will be recursively
deleted.
Expand Down
19 changes: 6 additions & 13 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,10 +1725,7 @@ def absent(name,
ret['comment'] = 'File {0} is set for removal'.format(name)
return ret
try:
if salt.utils.platform.is_windows():
__salt__['file.remove'](name, force=True)
else:
__salt__['file.remove'](name)
__salt__['file.remove'](name, force=True)
ret['comment'] = 'Removed file {0}'.format(name)
ret['changes']['removed'] = name
return ret
Expand All @@ -1742,10 +1739,7 @@ def absent(name,
ret['comment'] = 'Directory {0} is set for removal'.format(name)
return ret
try:
if salt.utils.platform.is_windows():
__salt__['file.remove'](name, force=True)
else:
__salt__['file.remove'](name)
__salt__['file.remove'](name, force=True)
ret['comment'] = 'Removed directory {0}'.format(name)
ret['changes']['removed'] = name
return ret
Expand Down Expand Up @@ -1862,10 +1856,7 @@ def _matches(name):
# Iterate over collected items
try:
for path in todelete:
if salt.utils.platform.is_windows():
__salt__['file.remove'](path, force=True)
else:
__salt__['file.remove'](path)
__salt__['file.remove'](path, force=True)
# Remember what we've removed, will appear in the summary
ret['changes']['removed'].append(path)
except CommandExecutionError as exc:
Expand Down Expand Up @@ -6766,7 +6757,9 @@ def copy_(name,
elif not __opts__['test'] and changed:
# Remove the destination to prevent problems later
try:
__salt__['file.remove'](name)
# On windows, if a file has the read-only attribute then we are unable
# to complete this copy unless force is set to true.
__salt__['file.remove'](name, force=force)
except (IOError, OSError):
return _error(
ret,
Expand Down

0 comments on commit 19a1882

Please sign in to comment.