|
|
@ -525,6 +525,9 @@ def main():
|
|
|
|
supports_check_mode=True,
|
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This should eventually be set by controller
|
|
|
|
|
|
|
|
setattr(module, 'digest', 'sha1')
|
|
|
|
|
|
|
|
|
|
|
|
src = module.params['src']
|
|
|
|
src = module.params['src']
|
|
|
|
b_src = to_bytes(src, errors='surrogate_or_strict')
|
|
|
|
b_src = to_bytes(src, errors='surrogate_or_strict')
|
|
|
|
dest = module.params['dest']
|
|
|
|
dest = module.params['dest']
|
|
|
@ -549,8 +552,8 @@ def main():
|
|
|
|
if not os.access(b_src, os.R_OK):
|
|
|
|
if not os.access(b_src, os.R_OK):
|
|
|
|
module.fail_json(msg="Source %s not readable" % (src))
|
|
|
|
module.fail_json(msg="Source %s not readable" % (src))
|
|
|
|
|
|
|
|
|
|
|
|
# Preserve is usually handled in the action plugin but mode + remote_src has to be done on the
|
|
|
|
# Preserve is usually handled in the action plugin but mode + remote_src has to be done here.
|
|
|
|
# remote host
|
|
|
|
# We are alterning 'params' as this is passed to functions later on.
|
|
|
|
if module.params['mode'] == 'preserve':
|
|
|
|
if module.params['mode'] == 'preserve':
|
|
|
|
module.params['mode'] = '0%03o' % stat.S_IMODE(os.stat(b_src).st_mode)
|
|
|
|
module.params['mode'] = '0%03o' % stat.S_IMODE(os.stat(b_src).st_mode)
|
|
|
|
mode = module.params['mode']
|
|
|
|
mode = module.params['mode']
|
|
|
@ -563,12 +566,12 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(src):
|
|
|
|
if os.path.isfile(src):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
checksum_src = module.sha1(src)
|
|
|
|
checksum_src = module.digest_from_file(src, module.digest)
|
|
|
|
except (OSError, IOError) as e:
|
|
|
|
except (OSError, IOError) as e:
|
|
|
|
module.warn("Unable to calculate src checksum, assuming change: %s" % to_native(e))
|
|
|
|
module.warn("Unable to calculate src checksum, assuming change: %s" % to_native(e))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Backwards compat only. This will be None in FIPS mode
|
|
|
|
# Backwards compat only. This will be None in FIPS mode
|
|
|
|
md5sum_src = module.md5(src)
|
|
|
|
md5sum_src = module.digest_from_file(src, 'md5')
|
|
|
|
except ValueError:
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
elif remote_src and not os.path.isdir(src):
|
|
|
|
elif remote_src and not os.path.isdir(src):
|
|
|
@ -621,7 +624,7 @@ def main():
|
|
|
|
if not force:
|
|
|
|
if not force:
|
|
|
|
module.exit_json(msg="file already exists", src=src, dest=dest, changed=False)
|
|
|
|
module.exit_json(msg="file already exists", src=src, dest=dest, changed=False)
|
|
|
|
if os.access(b_dest, os.R_OK) and os.path.isfile(b_dest):
|
|
|
|
if os.access(b_dest, os.R_OK) and os.path.isfile(b_dest):
|
|
|
|
checksum_dest = module.sha1(dest)
|
|
|
|
checksum_dest = module.digest_from_file(dest, module.digest)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if not os.path.exists(os.path.dirname(b_dest)):
|
|
|
|
if not os.path.exists(os.path.dirname(b_dest)):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -668,10 +671,12 @@ def main():
|
|
|
|
b_mysrc = b_src
|
|
|
|
b_mysrc = b_src
|
|
|
|
if remote_src and os.path.isfile(b_src):
|
|
|
|
if remote_src and os.path.isfile(b_src):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# create a destination tempfile on the same directory (assures same partition for rename)
|
|
|
|
dummy, b_mysrc = tempfile.mkstemp(dir=os.path.dirname(b_dest))
|
|
|
|
dummy, b_mysrc = tempfile.mkstemp(dir=os.path.dirname(b_dest))
|
|
|
|
|
|
|
|
|
|
|
|
shutil.copyfile(b_src, b_mysrc)
|
|
|
|
shutil.copy2(b_src, b_mysrc)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
# this might be 'noop' if above copies attributes, but jic and so we can give a warning
|
|
|
|
shutil.copystat(b_src, b_mysrc)
|
|
|
|
shutil.copystat(b_src, b_mysrc)
|
|
|
|
except OSError as err:
|
|
|
|
except OSError as err:
|
|
|
|
if err.errno == errno.ENOSYS and mode == "preserve":
|
|
|
|
if err.errno == errno.ENOSYS and mode == "preserve":
|
|
|
|