When putting a file in accelerated mode, make sure it's chowned correctly

This commit is contained in:
James Cammarata 2013-09-05 12:04:08 -05:00
parent 68bffb1233
commit f04af9118e

View file

@ -274,11 +274,13 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
return dict(failed=True, msg='internal error: out_path is required') return dict(failed=True, msg='internal error: out_path is required')
final_path = None final_path = None
final_user = None
if 'user' in data and data.get('user') != getpass.getuser(): if 'user' in data and data.get('user') != getpass.getuser():
log("the target user doesn't match this user, we'll move the file into place via sudo") log("the target user doesn't match this user, we'll move the file into place via sudo")
(fd,out_path) = tempfile.mkstemp(prefix='ansible.', dir=os.path.expanduser('~/.ansible/tmp/')) (fd,out_path) = tempfile.mkstemp(prefix='ansible.', dir=os.path.expanduser('~/.ansible/tmp/'))
out_fd = os.fdopen(fd, 'w', 0) out_fd = os.fdopen(fd, 'w', 0)
final_path = data['out_path'] final_path = data['out_path']
final_user = data['user']
else: else:
out_path = data['out_path'] out_path = data['out_path']
out_fd = open(out_path, 'w') out_fd = open(out_path, 'w')
@ -313,6 +315,10 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
rc, stdout, stderr = self.server.module.run_command(args, close_fds=True) rc, stdout, stderr = self.server.module.run_command(args, close_fds=True)
if rc != 0: if rc != 0:
return dict(failed=True, stdout="failed to copy the file into position with sudo") return dict(failed=True, stdout="failed to copy the file into position with sudo")
args = ['sudo','chown',final_user,out_path,final_path]
rc, stdout, stderr = self.server.module.run_command(args, close_fds=True)
if rc != 0:
return dict(failed=True, stdout="failed to chown the file via sudo")
return dict() return dict()
def daemonize(module, password, port, minutes): def daemonize(module, password, port, minutes):