Merge pull request #43304 from duk3luk3/feature-16313-file-recurse-replace

Feature: Add `replace` parameter to file.recurse state
This commit is contained in:
Nicole Thomas 2017-09-05 18:24:27 -04:00 committed by GitHub
commit cfc08147e9

View File

@ -3060,6 +3060,7 @@ def recurse(name,
sym_mode=None,
template=None,
context=None,
replace=True,
defaults=None,
include_empty=False,
backup='',
@ -3148,6 +3149,11 @@ def recurse(name,
The template option is required when recursively applying templates.
replace : True
If set to ``False`` and the file already exists, the file will not be
modified even if changes would otherwise be made. Permissions and
ownership will still be enforced, however.
context
Overrides default context variables passed to the template.
@ -3337,8 +3343,8 @@ def recurse(name,
if _ret['changes']:
ret['changes'][path] = _ret['changes']
def manage_file(path, source):
if clean and os.path.exists(path) and os.path.isdir(path):
def manage_file(path, source, replace):
if clean and os.path.exists(path) and os.path.isdir(path) and replace:
_ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
if __opts__['test']:
_ret['comment'] = u'Replacing directory {0} with a ' \
@ -3368,6 +3374,7 @@ def recurse(name,
attrs=None,
template=template,
makedirs=True,
replace=replace,
context=context,
defaults=defaults,
backup=backup,
@ -3424,7 +3431,7 @@ def recurse(name,
for dirname in mng_dirs:
manage_directory(dirname)
for dest, src in mng_files:
manage_file(dest, src)
manage_file(dest, src, replace)
if clean:
# TODO: Use directory(clean=True) instead