1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix a traceback with python3 and diff output

When retrieving file contents for diffing we need to get the contents as
binary.  Otherwise python3 will try to convert the file to text and fail
with non-decodable contents.

Fixes #23171
This commit is contained in:
Toshio Kuratomi 2017-04-07 10:20:18 -07:00
parent d4bd54d3b8
commit 2fdb8e7f90

View file

@ -952,12 +952,12 @@ class ActionBase(with_metaclass(ABCMeta, object)):
else:
display.debug("Reading local copy of the file %s" % source)
try:
src = open(source)
src_contents = src.read()
with open(source, 'rb') as src:
src_contents = src.read()
except Exception as e:
raise AnsibleError("Unexpected error while reading source (%s) for diff: %s " % (source, str(e)))
if "\x00" in src_contents:
if b"\x00" in src_contents:
diff['src_binary'] = 1
else:
diff['after_header'] = source