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

fixed case in which move fails after remote user copies file and sudo to non root does the move

Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
This commit is contained in:
Brian Coca 2013-05-03 21:58:27 -04:00
parent c3547a2308
commit bdeb370d79

View file

@ -836,8 +836,11 @@ class AnsibleModule(object):
except OSError, e:
sys.stderr.write("could not cleanup %s: %s" % (tmp_dest, e))
try:
shutil.move(src, tmp_dest)
try: # leaves tmp file behind when sudo and not root
if os.getenv("SUDO_USER") and os.getuid() != 0:
shutil.copy(src, tmp_dest)
else:
shutil.move(src, tmp_dest)
if self.selinux_enabled():
self.set_context_if_different(tmp_dest, context, False)
os.rename(tmp_dest, dest)