1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add copy module support for filesystems without chmod (#40099)

* only relevant to remote_src=True
* separate file content copying from file stats copying
* raise exception on mode='preserve', ignore otherwise

Fixes: #19731
Signed-off-by: Nikita Chepanov <nchepanov@bloomberg.net>
This commit is contained in:
Nikita Chepanov 2018-05-14 16:17:38 -04:00 committed by Toshio Kuratomi
parent 7d221c4663
commit 9514a618b7

View file

@ -233,6 +233,7 @@ import os
import os.path import os.path
import shutil import shutil
import stat import stat
import errno
import tempfile import tempfile
import traceback import traceback
@ -408,9 +409,17 @@ def main():
b_mysrc = b_src b_mysrc = b_src
if remote_src: if remote_src:
_, b_mysrc = tempfile.mkstemp(dir=os.path.dirname(b_dest)) _, b_mysrc = tempfile.mkstemp(dir=os.path.dirname(b_dest))
shutil.copy2(b_src, b_mysrc)
shutil.copyfile(b_src, b_mysrc)
try:
shutil.copystat(b_src, b_mysrc)
except OSError as err:
if err.errno == errno.ENOSYS and mode == "preserve":
module.warn("Unable to copy stats {0}".format(to_native(b_src)))
else:
raise
module.atomic_move(b_mysrc, dest, unsafe_writes=module.params['unsafe_writes']) module.atomic_move(b_mysrc, dest, unsafe_writes=module.params['unsafe_writes'])
except IOError: except (IOError, OSError):
module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc()) module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc())
changed = True changed = True
else: else: