mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix UnicodeDecodeError in for binary file contents.
This patch fixes a UnicodeDecodeError being raised when using file.managed with binary contents and the test mode is set to True.
This commit is contained in:
parent
67bf6b5f22
commit
50957e8a58
1 changed files with 15 additions and 8 deletions
|
@ -5443,15 +5443,22 @@ def check_file_meta(
|
|||
|
||||
if contents is not None:
|
||||
# Write a tempfile with the static contents
|
||||
tmp = salt.utils.files.mkstemp(
|
||||
prefix=salt.utils.files.TEMPFILE_PREFIX, text=True
|
||||
)
|
||||
if salt.utils.platform.is_windows():
|
||||
contents = os.linesep.join(
|
||||
_splitlines_preserving_trailing_newline(contents)
|
||||
if isinstance(contents, six.binary_type):
|
||||
tmp = salt.utils.files.mkstemp(
|
||||
prefix=salt.utils.files.TEMPFILE_PREFIX, text=False
|
||||
)
|
||||
with salt.utils.files.fopen(tmp, "w") as tmp_:
|
||||
tmp_.write(salt.utils.stringutils.to_str(contents))
|
||||
with salt.utils.files.fopen(tmp, 'wb') as tmp_:
|
||||
tmp_.write(contents)
|
||||
else:
|
||||
tmp = salt.utils.files.mkstemp(
|
||||
prefix=salt.utils.files.TEMPFILE_PREFIX, text=True
|
||||
)
|
||||
if salt.utils.platform.is_windows():
|
||||
contents = os.linesep.join(
|
||||
_splitlines_preserving_trailing_newline(contents)
|
||||
)
|
||||
with salt.utils.files.fopen(tmp, "w") as tmp_:
|
||||
tmp_.write(salt.utils.stringutils.to_str(contents))
|
||||
# Compare the static contents with the named file
|
||||
try:
|
||||
differences = get_diff(name, tmp, show_filenames=False)
|
||||
|
|
Loading…
Add table
Reference in a new issue