made max diff size configurable

This commit is contained in:
Brian Coca 2016-02-10 11:23:49 -05:00
parent e438a26ada
commit c24249c57d
3 changed files with 8 additions and 3 deletions

View file

@ -198,6 +198,10 @@
# is used. This value must be an integer from 0 to 9. # is used. This value must be an integer from 0 to 9.
#var_compression_level = 9 #var_compression_level = 9
# This controls the cutoff point (in bytes) on --diff for files
# set to 0 for unlimited (RAM may suffer!).
#max_diff_size = 1048576
[privilege_escalation] [privilege_escalation]
#become=True #become=True
#become_method=sudo #become_method=sudo

View file

@ -239,6 +239,7 @@ RETRY_FILES_ENABLED = get_config(p, DEFAULTS, 'retry_files_enabled',
RETRY_FILES_SAVE_PATH = get_config(p, DEFAULTS, 'retry_files_save_path', 'ANSIBLE_RETRY_FILES_SAVE_PATH', None, ispath=True) RETRY_FILES_SAVE_PATH = get_config(p, DEFAULTS, 'retry_files_save_path', 'ANSIBLE_RETRY_FILES_SAVE_PATH', None, ispath=True)
DEFAULT_NULL_REPRESENTATION = get_config(p, DEFAULTS, 'null_representation', 'ANSIBLE_NULL_REPRESENTATION', None, isnone=True) DEFAULT_NULL_REPRESENTATION = get_config(p, DEFAULTS, 'null_representation', 'ANSIBLE_NULL_REPRESENTATION', None, isnone=True)
DISPLAY_ARGS_TO_STDOUT = get_config(p, DEFAULTS, 'display_args_to_stdout', 'ANSIBLE_DISPLAY_ARGS_TO_STDOUT', False, boolean=True) DISPLAY_ARGS_TO_STDOUT = get_config(p, DEFAULTS, 'display_args_to_stdout', 'ANSIBLE_DISPLAY_ARGS_TO_STDOUT', False, boolean=True)
MAX_FILE_SIZE_FOR_DIFF = get_config(p, DEFAULTS, 'max_diff_size', 'ANSIBLE_MAX_DIFF_SIZE', 1024*1024, integer=True)
# CONNECTION RELATED # CONNECTION RELATED
ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', '-o ControlMaster=auto -o ControlPersist=60s') ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', '-o ControlMaster=auto -o ControlPersist=60s')
@ -298,6 +299,5 @@ DEFAULT_SUBSET = None
DEFAULT_SU_PASS = None DEFAULT_SU_PASS = None
VAULT_VERSION_MIN = 1.0 VAULT_VERSION_MIN = 1.0
VAULT_VERSION_MAX = 1.0 VAULT_VERSION_MAX = 1.0
MAX_FILE_SIZE_FOR_DIFF = 1*1024*1024
TREE_DIR = None TREE_DIR = None
LOCALHOST = frozenset(['127.0.0.1', 'localhost', '::1']) LOCALHOST = frozenset(['127.0.0.1', 'localhost', '::1'])

View file

@ -615,7 +615,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
diff['before'] = '' diff['before'] = ''
elif peek_result['appears_binary']: elif peek_result['appears_binary']:
diff['dst_binary'] = 1 diff['dst_binary'] = 1
elif peek_result['size'] > C.MAX_FILE_SIZE_FOR_DIFF: elif C.MAX_FILE_SIZE_FOR_DIFF > 0 and peek_result['size'] > C.MAX_FILE_SIZE_FOR_DIFF:
diff['dst_larger'] = C.MAX_FILE_SIZE_FOR_DIFF diff['dst_larger'] = C.MAX_FILE_SIZE_FOR_DIFF
else: else:
display.debug("Slurping the file %s" % source) display.debug("Slurping the file %s" % source)
@ -631,7 +631,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
if source_file: if source_file:
st = os.stat(source) st = os.stat(source)
if st[stat.ST_SIZE] > C.MAX_FILE_SIZE_FOR_DIFF: if C.MAX_FILE_SIZE_FOR_DIFF > 0 and st[stat.ST_SIZE] > C.MAX_FILE_SIZE_FOR_DIFF:
diff['src_larger'] = C.MAX_FILE_SIZE_FOR_DIFF diff['src_larger'] = C.MAX_FILE_SIZE_FOR_DIFF
else: else:
display.debug("Reading local copy of the file %s" % source) display.debug("Reading local copy of the file %s" % source)
@ -640,6 +640,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
src_contents = src.read() src_contents = src.read()
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
else: else: