fix insertion of newfile key in changes dict for windows

This commit is contained in:
nicholasmhughes 2024-02-19 10:35:04 -05:00 committed by Daniel Wozniak
parent 00292d6b0d
commit 0d518807e2
3 changed files with 9 additions and 8 deletions

View file

@ -5755,7 +5755,7 @@ def check_managed_changes(
If ``True``, creation of new files will still show a diff in the
changes return.
.. versionadded:: 3007.0
.. versionadded:: 3008.0
CLI Example:
@ -5976,7 +5976,7 @@ def check_file_meta(
If ``True``, creation of new files will still show a diff in the
changes return.
.. versionadded:: 3007.0
.. versionadded:: 3008.0
"""
changes = {}
has_changes = False
@ -6587,7 +6587,7 @@ def manage_file(
If ``True``, creation of new files will still show a diff in the
changes return.
.. versionadded:: 3007.0
.. versionadded:: 3008.0
CLI Example:

View file

@ -3021,7 +3021,7 @@ def managed(
If ``True``, creation of new files will still show a diff in the
changes return.
.. versionadded:: 3007.0
.. versionadded:: 3008.0
"""
if "env" in kwargs:
# "env" is not supported; Use "saltenv".
@ -3370,9 +3370,11 @@ def managed(
reset=win_perms_reset,
)
except CommandExecutionError as exc:
if not isinstance(
ret["changes"], tuple
) and exc.strerror.startswith("Path not found"):
if (
not isinstance(ret["changes"], tuple)
and exc.strerror.startswith("Path not found")
and not new_file_diff
):
ret["changes"]["newfile"] = name
if isinstance(ret["changes"], tuple):

View file

@ -1050,7 +1050,6 @@ def test_file_managed_new_file_diff(file, tmp_path):
ret = file.managed(str(name), contents="EITR", new_file_diff=True, test=True)
assert ret.changes == {
"diff": f"--- \n+++ \n@@ -0,0 +1 @@\n+EITR{os.linesep}",
"newfile": str(name),
}
assert not name.exists()
ret = file.managed(str(name), contents="EITR", new_file_diff=True)