mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
read full file when doing diff
but avoid reading file at all or full file when file is too big for diffing
This commit is contained in:
parent
d9dcb2a427
commit
3079a03773
1 changed files with 13 additions and 12 deletions
|
@ -600,20 +600,21 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
|||
diff['before'] = dest_contents
|
||||
|
||||
if source_file:
|
||||
display.debug("Reading local copy of the file %s" % source)
|
||||
try:
|
||||
src = open(source)
|
||||
src_contents = src.read(8192)
|
||||
st = os.stat(source)
|
||||
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:
|
||||
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:
|
||||
diff['after_header'] = source
|
||||
diff['after'] = src_contents
|
||||
display.debug("Reading local copy of the file %s" % source)
|
||||
try:
|
||||
src = open(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
|
||||
else:
|
||||
diff['after_header'] = source
|
||||
diff['after'] = src_contents
|
||||
else:
|
||||
display.debug("source of file passed in")
|
||||
diff['after_header'] = 'dynamically generated'
|
||||
|
|
Loading…
Reference in a new issue