Merge pull request #14416 from bcoca/diff_size_fix

read full file when doing diff
This commit is contained in:
Brian Coca 2016-02-10 15:42:29 -05:00
commit 64c976a6c3

View file

@ -600,17 +600,18 @@ class ActionBase(with_metaclass(ABCMeta, object)):
diff['before'] = dest_contents
if source_file:
st = os.stat(source)
if st[stat.ST_SIZE] > C.MAX_FILE_SIZE_FOR_DIFF:
diff['src_larger'] = C.MAX_FILE_SIZE_FOR_DIFF
else:
display.debug("Reading local copy of the file %s" % source)
try:
src = open(source)
src_contents = src.read(8192)
st = os.stat(source)
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:
diff['src_binary'] = 1
elif st[stat.ST_SIZE] > C.MAX_FILE_SIZE_FOR_DIFF:
diff['src_larger'] = C.MAX_FILE_SIZE_FOR_DIFF
else:
diff['after_header'] = source
diff['after'] = src_contents