read full file when doing diff

but avoid reading file at all or full file when file is too big for diffing
pull/14416/head
Brian Coca 9 years ago
parent d9dcb2a427
commit 3079a03773

@ -600,17 +600,18 @@ class ActionBase(with_metaclass(ABCMeta, object)):
diff['before'] = dest_contents diff['before'] = dest_contents
if source_file: 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) display.debug("Reading local copy of the file %s" % source)
try: try:
src = open(source) src = open(source)
src_contents = src.read(8192) src_contents = src.read()
st = os.stat(source)
except Exception as e: except Exception as e:
raise AnsibleError("Unexpected error while reading source (%s) for diff: %s " % (source, str(e))) raise AnsibleError("Unexpected error while reading source (%s) for diff: %s " % (source, str(e)))
if "\x00" in src_contents: if "\x00" in src_contents:
diff['src_binary'] = 1 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: else:
diff['after_header'] = source diff['after_header'] = source
diff['after'] = src_contents diff['after'] = src_contents

Loading…
Cancel
Save