2014-01-04 18:31:44 +00:00
|
|
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
2012-09-06 22:57:04 +00:00
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from ansible import utils
|
2014-02-04 18:44:10 +00:00
|
|
|
import ansible.constants as C
|
2013-04-10 23:09:57 +00:00
|
|
|
import ansible.utils.template as template
|
2012-09-06 22:57:04 +00:00
|
|
|
from ansible import errors
|
|
|
|
from ansible.runner.return_data import ReturnData
|
2013-02-25 22:32:52 +00:00
|
|
|
import base64
|
2014-02-18 19:23:44 +00:00
|
|
|
import json
|
2013-02-25 22:32:52 +00:00
|
|
|
import stat
|
2013-03-04 16:32:25 +00:00
|
|
|
import tempfile
|
2013-03-11 21:11:53 +00:00
|
|
|
import pipes
|
2012-09-06 22:57:04 +00:00
|
|
|
|
2013-08-08 20:09:45 +00:00
|
|
|
## fixes https://github.com/ansible/ansible/issues/3518
|
|
|
|
# http://mypy.pythonblogs.com/12_mypy/archive/1253_workaround_for_python_bug_ascii_codec_cant_encode_character_uxa0_in_position_111_ordinal_not_in_range128.html
|
|
|
|
import sys
|
|
|
|
reload(sys)
|
|
|
|
sys.setdefaultencoding("utf8")
|
|
|
|
|
|
|
|
|
2012-09-06 22:57:04 +00:00
|
|
|
class ActionModule(object):
|
|
|
|
|
|
|
|
def __init__(self, runner):
|
|
|
|
self.runner = runner
|
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
def run(self, conn, tmp_path, module_name, module_args, inject, complex_args=None, **kwargs):
|
2012-09-06 22:57:04 +00:00
|
|
|
''' handler for file transfer operations '''
|
|
|
|
|
|
|
|
# load up options
|
2013-02-28 13:27:42 +00:00
|
|
|
options = {}
|
|
|
|
if complex_args:
|
|
|
|
options.update(complex_args)
|
|
|
|
options.update(utils.parse_kv(module_args))
|
2014-02-26 18:33:17 +00:00
|
|
|
source = options.get('src', None)
|
2013-03-04 16:32:25 +00:00
|
|
|
content = options.get('content', None)
|
2014-02-26 18:33:17 +00:00
|
|
|
dest = options.get('dest', None)
|
2013-07-22 12:25:35 +00:00
|
|
|
raw = utils.boolean(options.get('raw', 'no'))
|
2013-04-07 02:20:10 +00:00
|
|
|
force = utils.boolean(options.get('force', 'yes'))
|
2012-10-13 00:07:05 +00:00
|
|
|
|
2014-03-05 23:49:54 +00:00
|
|
|
# content with newlines is going to be escaped to safely load in yaml
|
|
|
|
# now we need to unescape it so that the newlines are evaluated properly
|
|
|
|
# when writing the file to disk
|
|
|
|
if content:
|
2014-03-17 16:14:29 +00:00
|
|
|
if isinstance(content, unicode):
|
|
|
|
try:
|
|
|
|
content = content.decode('unicode-escape')
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
pass
|
2014-03-05 23:49:54 +00:00
|
|
|
|
2013-03-04 16:32:25 +00:00
|
|
|
if (source is None and content is None and not 'first_available_file' in inject) or dest is None:
|
2013-03-18 03:32:59 +00:00
|
|
|
result=dict(failed=True, msg="src (or content) and dest are required")
|
2013-03-04 16:32:25 +00:00
|
|
|
return ReturnData(conn=conn, result=result)
|
|
|
|
elif (source is not None or 'first_available_file' in inject) and content is not None:
|
|
|
|
result=dict(failed=True, msg="src and content are mutually exclusive")
|
2012-09-06 22:57:04 +00:00
|
|
|
return ReturnData(conn=conn, result=result)
|
|
|
|
|
2014-02-26 21:29:00 +00:00
|
|
|
# Check if the source ends with a "/"
|
2013-10-04 18:58:49 +00:00
|
|
|
source_trailing_slash = False
|
|
|
|
if source:
|
|
|
|
source_trailing_slash = source.endswith("/")
|
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# Define content_tempfile in case we set it after finding content populated.
|
|
|
|
content_tempfile = None
|
|
|
|
|
|
|
|
# If content is defined make a temp file and write the content into it.
|
|
|
|
if content is not None:
|
|
|
|
try:
|
2014-02-18 19:23:44 +00:00
|
|
|
# If content comes to us as a dict it should be decoded json.
|
|
|
|
# We need to encode it back into a string to write it out.
|
|
|
|
if type(content) is dict:
|
|
|
|
content_tempfile = self._create_content_tempfile(json.dumps(content))
|
|
|
|
else:
|
|
|
|
content_tempfile = self._create_content_tempfile(content)
|
2014-02-04 18:44:10 +00:00
|
|
|
source = content_tempfile
|
|
|
|
except Exception, err:
|
|
|
|
result = dict(failed=True, msg="could not write content temp file: %s" % err)
|
|
|
|
return ReturnData(conn=conn, result=result)
|
2012-09-06 22:57:04 +00:00
|
|
|
# if we have first_available_file in our vars
|
|
|
|
# look up the files and use the first one we find as src
|
2014-02-04 18:44:10 +00:00
|
|
|
elif 'first_available_file' in inject:
|
2012-09-06 22:57:04 +00:00
|
|
|
found = False
|
|
|
|
for fn in inject.get('first_available_file'):
|
2013-04-12 03:40:23 +00:00
|
|
|
fn_orig = fn
|
2013-06-03 20:47:50 +00:00
|
|
|
fnt = template.template(self.runner.basedir, fn, inject)
|
|
|
|
fnd = utils.path_dwim(self.runner.basedir, fnt)
|
|
|
|
if not os.path.exists(fnd) and '_original_file' in inject:
|
|
|
|
fnd = utils.path_dwim_relative(inject['_original_file'], 'files', fnt, self.runner.basedir, check=False)
|
|
|
|
if os.path.exists(fnd):
|
|
|
|
source = fnd
|
2012-09-06 22:57:04 +00:00
|
|
|
found = True
|
|
|
|
break
|
|
|
|
if not found:
|
2014-02-04 18:44:10 +00:00
|
|
|
results = dict(failed=True, msg="could not find src in first_available_file list")
|
2012-11-19 22:02:26 +00:00
|
|
|
return ReturnData(conn=conn, result=results)
|
2013-01-09 13:52:52 +00:00
|
|
|
else:
|
2013-04-10 21:52:35 +00:00
|
|
|
source = template.template(self.runner.basedir, source, inject)
|
2013-04-06 16:13:04 +00:00
|
|
|
if '_original_file' in inject:
|
|
|
|
source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir)
|
|
|
|
else:
|
|
|
|
source = utils.path_dwim(self.runner.basedir, source)
|
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# A list of source file tuples (full_path, relative_path) which will try to copy to the destination
|
2013-10-04 18:58:49 +00:00
|
|
|
source_files = []
|
2014-02-04 18:44:10 +00:00
|
|
|
|
|
|
|
# If source is a directory populate our list else source is a file and translate it to a tuple.
|
2013-10-04 18:58:49 +00:00
|
|
|
if os.path.isdir(source):
|
2014-02-04 18:44:10 +00:00
|
|
|
# Get the amount of spaces to remove to get the relative path.
|
2013-10-04 18:58:49 +00:00
|
|
|
if source_trailing_slash:
|
|
|
|
sz = len(source) + 1
|
|
|
|
else:
|
|
|
|
sz = len(source.rsplit('/', 1)[0]) + 1
|
2014-02-04 18:44:10 +00:00
|
|
|
|
|
|
|
# Walk the directory and append the file tuples to source_files.
|
2013-10-04 18:58:49 +00:00
|
|
|
for base_path, sub_folders, files in os.walk(source):
|
|
|
|
for file in files:
|
|
|
|
full_path = os.path.join(base_path, file)
|
|
|
|
rel_path = full_path[sz:]
|
|
|
|
source_files.append((full_path, rel_path))
|
2014-02-04 18:44:10 +00:00
|
|
|
|
2013-10-14 19:09:45 +00:00
|
|
|
# If it's recursive copy, destination is always a dir,
|
2014-02-04 18:44:10 +00:00
|
|
|
# explicitly mark it so (note - copy module relies on this).
|
2013-10-14 19:09:45 +00:00
|
|
|
if not dest.endswith("/"):
|
|
|
|
dest += "/"
|
2013-10-04 18:58:49 +00:00
|
|
|
else:
|
|
|
|
source_files.append((source, os.path.basename(source)))
|
|
|
|
|
|
|
|
changed = False
|
|
|
|
diffs = []
|
2013-10-14 19:08:03 +00:00
|
|
|
module_result = {"changed": False}
|
2014-02-04 18:44:10 +00:00
|
|
|
|
2014-02-08 08:25:42 +00:00
|
|
|
# A register for if we executed a module.
|
|
|
|
# Used to cut down on command calls when not recursive.
|
|
|
|
module_executed = False
|
|
|
|
|
|
|
|
# Tell _execute_module to delete the file if there is one file.
|
|
|
|
delete_remote_tmp = (len(source_files) == 1)
|
|
|
|
|
|
|
|
# If this is a recursive action create a tmp_path that we can share as the _exec_module create is too late.
|
|
|
|
if not delete_remote_tmp:
|
|
|
|
if "-tmp-" not in tmp_path:
|
|
|
|
tmp_path = self.runner._make_tmp_path(conn)
|
2014-02-04 18:44:10 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
for source_full, source_rel in source_files:
|
2014-02-04 18:44:10 +00:00
|
|
|
# Generate the MD5 hash of the local file.
|
2013-10-04 18:58:49 +00:00
|
|
|
local_md5 = utils.md5(source_full)
|
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# If local_md5 is not defined we can't find the file so we should fail out.
|
2013-10-04 18:58:49 +00:00
|
|
|
if local_md5 is None:
|
2014-02-04 18:44:10 +00:00
|
|
|
result = dict(failed=True, msg="could not find src=%s" % source_full)
|
2013-03-04 16:32:25 +00:00
|
|
|
return ReturnData(conn=conn, result=result)
|
2013-02-04 00:46:25 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
# This is kind of optimization - if user told us destination is
|
|
|
|
# dir, do path manipulation right away, otherwise we still check
|
|
|
|
# for dest being a dir via remote call below.
|
|
|
|
if dest.endswith("/"):
|
|
|
|
dest_file = os.path.join(dest, source_rel)
|
2013-02-25 22:32:52 +00:00
|
|
|
else:
|
2013-10-04 18:58:49 +00:00
|
|
|
dest_file = dest
|
2013-02-25 22:32:52 +00:00
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# Attempt to get the remote MD5 Hash.
|
|
|
|
remote_md5 = self.runner._remote_md5(conn, tmp_path, dest_file)
|
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if remote_md5 == '3':
|
2014-02-04 18:44:10 +00:00
|
|
|
# The remote_md5 was executed on a directory.
|
2013-03-04 16:32:25 +00:00
|
|
|
if content is not None:
|
2014-02-04 18:44:10 +00:00
|
|
|
# If source was defined as content remove the temporary file and fail out.
|
|
|
|
self._remove_tempfile_if_content_defined(content, content_tempfile)
|
2013-10-04 18:58:49 +00:00
|
|
|
result = dict(failed=True, msg="can not use content with a dir as dest")
|
|
|
|
return ReturnData(conn=conn, result=result)
|
2014-02-04 18:44:10 +00:00
|
|
|
else:
|
|
|
|
# Append the relative source location to the destination and retry remote_md5.
|
|
|
|
dest_file = os.path.join(dest, source_rel)
|
|
|
|
remote_md5 = self.runner._remote_md5(conn, tmp_path, dest_file)
|
2013-02-04 00:46:25 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if remote_md5 != '1' and not force:
|
2014-02-04 18:44:10 +00:00
|
|
|
# remote_file does not exist so continue to next iteration.
|
2013-10-04 18:58:49 +00:00
|
|
|
continue
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if local_md5 != remote_md5:
|
2014-02-04 18:44:10 +00:00
|
|
|
# The MD5 hashes don't match and we will change or error out.
|
2013-10-04 18:58:49 +00:00
|
|
|
changed = True
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2014-02-08 08:25:42 +00:00
|
|
|
# Create a tmp_path if missing only if this is not recursive.
|
|
|
|
# If this is recursive we already have a tmp_path.
|
|
|
|
if delete_remote_tmp:
|
|
|
|
if "-tmp-" not in tmp_path:
|
|
|
|
tmp_path = self.runner._make_tmp_path(conn)
|
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if self.runner.diff and not raw:
|
2014-02-04 18:44:10 +00:00
|
|
|
diff = self._get_diff_data(conn, tmp_path, inject, dest_file, source_full)
|
2013-10-04 18:58:49 +00:00
|
|
|
else:
|
|
|
|
diff = {}
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if self.runner.noop_on_check(inject):
|
2014-02-04 18:44:10 +00:00
|
|
|
self._remove_tempfile_if_content_defined(content, content_tempfile)
|
2013-10-04 18:58:49 +00:00
|
|
|
diffs.append(diff)
|
2013-10-14 19:08:03 +00:00
|
|
|
changed = True
|
|
|
|
module_result = dict(changed=True)
|
2013-10-04 18:58:49 +00:00
|
|
|
continue
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# Define a remote directory that we will copy the file to.
|
|
|
|
tmp_src = tmp_path + 'source'
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if not raw:
|
|
|
|
conn.put_file(source_full, tmp_src)
|
|
|
|
else:
|
|
|
|
conn.put_file(source_full, dest_file)
|
2013-02-04 00:46:25 +00:00
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# We have copied the file remotely and no longer require our content_tempfile
|
|
|
|
self._remove_tempfile_if_content_defined(content, content_tempfile)
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
# fix file permissions when the copy is done as a different user
|
|
|
|
if self.runner.sudo and self.runner.sudo_user != 'root' and not raw:
|
2014-02-04 18:44:10 +00:00
|
|
|
self.runner._low_level_exec_command(conn, "chmod a+r %s" % tmp_src, tmp_path)
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if raw:
|
2014-02-04 18:44:10 +00:00
|
|
|
# Continue to next iteration if raw is defined.
|
2013-10-04 18:58:49 +00:00
|
|
|
continue
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
# Run the copy module
|
2012-09-06 22:57:04 +00:00
|
|
|
|
2013-10-14 19:09:45 +00:00
|
|
|
# src and dest here come after original and override them
|
2014-02-04 18:44:10 +00:00
|
|
|
# we pass dest only to make sure it includes trailing slash in case of recursive copy
|
2013-10-14 19:09:45 +00:00
|
|
|
module_args_tmp = "%s src=%s dest=%s original_basename=%s" % (module_args,
|
|
|
|
pipes.quote(tmp_src), pipes.quote(dest), pipes.quote(source_rel))
|
2014-04-29 13:52:09 +00:00
|
|
|
|
|
|
|
if self.runner.no_log:
|
|
|
|
module_args_tmp = "%s NO_LOG=True" % module_args_tmp
|
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
module_return = self.runner._execute_module(conn, tmp_path, 'copy', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp)
|
2014-02-08 08:25:42 +00:00
|
|
|
module_executed = True
|
2013-07-22 12:25:35 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
else:
|
|
|
|
# no need to transfer the file, already correct md5, but still need to call
|
|
|
|
# the file module in case we want to change attributes
|
2014-02-04 18:44:10 +00:00
|
|
|
self._remove_tempfile_if_content_defined(content, content_tempfile)
|
2012-09-06 22:57:04 +00:00
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
if raw:
|
2014-02-04 18:44:10 +00:00
|
|
|
# Continue to next iteration if raw is defined.
|
|
|
|
# self.runner._remove_tmp_path(conn, tmp_path)
|
2013-10-04 18:58:49 +00:00
|
|
|
continue
|
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
tmp_src = tmp_path + source_rel
|
|
|
|
|
|
|
|
# Build temporary module_args.
|
2013-10-14 19:10:27 +00:00
|
|
|
module_args_tmp = "%s src=%s original_basename=%s" % (module_args,
|
|
|
|
pipes.quote(tmp_src), pipes.quote(source_rel))
|
2013-10-04 18:58:49 +00:00
|
|
|
if self.runner.noop_on_check(inject):
|
2013-10-14 09:36:21 +00:00
|
|
|
module_args_tmp = "%s CHECKMODE=True" % module_args_tmp
|
2014-01-31 22:09:10 +00:00
|
|
|
if self.runner.no_log:
|
|
|
|
module_args_tmp = "%s NO_LOG=True" % module_args_tmp
|
2014-02-04 18:44:10 +00:00
|
|
|
|
|
|
|
# Execute the file module.
|
|
|
|
module_return = self.runner._execute_module(conn, tmp_path, 'file', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp)
|
2014-02-08 08:25:42 +00:00
|
|
|
module_executed = True
|
2013-10-04 18:58:49 +00:00
|
|
|
|
|
|
|
module_result = module_return.result
|
2014-02-19 21:31:19 +00:00
|
|
|
if not module_result.get('md5sum'):
|
|
|
|
module_result['md5sum'] = local_md5
|
2013-10-04 18:58:49 +00:00
|
|
|
if module_result.get('failed') == True:
|
|
|
|
return module_return
|
|
|
|
if module_result.get('changed') == True:
|
|
|
|
changed = True
|
|
|
|
|
2014-02-08 08:25:42 +00:00
|
|
|
# Delete tmp_path if we were recursive or if we did not execute a module.
|
|
|
|
if (not C.DEFAULT_KEEP_REMOTE_FILES and not delete_remote_tmp) \
|
|
|
|
or (not C.DEFAULT_KEEP_REMOTE_FILES and delete_remote_tmp and not module_executed):
|
|
|
|
self.runner._remove_tmp_path(conn, tmp_path)
|
|
|
|
|
2014-02-19 21:31:19 +00:00
|
|
|
# the file module returns the file path as 'path', but
|
|
|
|
# the copy module uses 'dest', so add it if it's not there
|
|
|
|
if 'path' in module_result and 'dest' not in module_result:
|
|
|
|
module_result['dest'] = module_result['path']
|
|
|
|
|
2013-10-04 18:58:49 +00:00
|
|
|
# TODO: Support detailed status/diff for multiple files
|
|
|
|
if len(source_files) == 1:
|
|
|
|
result = module_result
|
2012-09-06 22:57:04 +00:00
|
|
|
else:
|
2013-10-04 18:58:49 +00:00
|
|
|
result = dict(dest=dest, src=source, changed=changed)
|
|
|
|
if len(diffs) == 1:
|
|
|
|
return ReturnData(conn=conn, result=result, diff=diffs[0])
|
|
|
|
else:
|
|
|
|
return ReturnData(conn=conn, result=result)
|
2012-09-06 22:57:04 +00:00
|
|
|
|
2014-02-04 18:44:10 +00:00
|
|
|
def _create_content_tempfile(self, content):
|
|
|
|
''' Create a tempfile containing defined content '''
|
|
|
|
fd, content_tempfile = tempfile.mkstemp()
|
|
|
|
f = os.fdopen(fd, 'w')
|
|
|
|
try:
|
|
|
|
f.write(content)
|
|
|
|
except Exception, err:
|
|
|
|
os.remove(content_tempfile)
|
|
|
|
raise Exception(err)
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
return content_tempfile
|
|
|
|
|
2013-02-25 22:32:52 +00:00
|
|
|
def _get_diff_data(self, conn, tmp, inject, destination, source):
|
|
|
|
peek_result = self.runner._execute_module(conn, tmp, 'file', "path=%s diff_peek=1" % destination, inject=inject, persist_files=True)
|
|
|
|
|
|
|
|
if not peek_result.is_successful():
|
|
|
|
return {}
|
|
|
|
|
|
|
|
diff = {}
|
|
|
|
if peek_result.result['state'] == 'absent':
|
|
|
|
diff['before'] = ''
|
|
|
|
elif peek_result.result['appears_binary']:
|
|
|
|
diff['dst_binary'] = 1
|
|
|
|
elif peek_result.result['size'] > utils.MAX_FILE_SIZE_FOR_DIFF:
|
|
|
|
diff['dst_larger'] = utils.MAX_FILE_SIZE_FOR_DIFF
|
|
|
|
else:
|
|
|
|
dest_result = self.runner._execute_module(conn, tmp, 'slurp', "path=%s" % destination, inject=inject, persist_files=True)
|
|
|
|
if 'content' in dest_result.result:
|
|
|
|
dest_contents = dest_result.result['content']
|
|
|
|
if dest_result.result['encoding'] == 'base64':
|
|
|
|
dest_contents = base64.b64decode(dest_contents)
|
|
|
|
else:
|
|
|
|
raise Exception("unknown encoding, failed: %s" % dest_result.result)
|
2013-02-26 15:53:59 +00:00
|
|
|
diff['before_header'] = destination
|
2013-02-25 22:32:52 +00:00
|
|
|
diff['before'] = dest_contents
|
|
|
|
|
|
|
|
src = open(source)
|
|
|
|
src_contents = src.read(8192)
|
|
|
|
st = os.stat(source)
|
2014-01-23 15:02:17 +00:00
|
|
|
if "\x00" in src_contents:
|
2013-02-25 22:32:52 +00:00
|
|
|
diff['src_binary'] = 1
|
|
|
|
elif st[stat.ST_SIZE] > utils.MAX_FILE_SIZE_FOR_DIFF:
|
|
|
|
diff['src_larger'] = utils.MAX_FILE_SIZE_FOR_DIFF
|
|
|
|
else:
|
|
|
|
src.seek(0)
|
2013-02-26 15:53:59 +00:00
|
|
|
diff['after_header'] = source
|
2013-02-25 22:32:52 +00:00
|
|
|
diff['after'] = src.read()
|
|
|
|
|
|
|
|
return diff
|
2014-02-04 18:44:10 +00:00
|
|
|
|
|
|
|
def _remove_tempfile_if_content_defined(self, content, content_tempfile):
|
|
|
|
if content is not None:
|
|
|
|
os.remove(content_tempfile)
|
|
|
|
|
2013-10-29 02:50:55 +00:00
|
|
|
|
|
|
|
def _result_key_merge(self, options, results):
|
|
|
|
# add keys to file module results to mimic copy
|
|
|
|
if 'path' in results.result and 'dest' not in results.result:
|
|
|
|
results.result['dest'] = results.result['path']
|
|
|
|
del results.result['path']
|
|
|
|
return results
|