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

Fix bug where spaces in the $HOME directory broke things

Fixes #11332
This commit is contained in:
James Cammarata 2015-07-20 15:40:22 -04:00
parent 91a4b866b0
commit 3de6f264dd

View file

@ -64,10 +64,10 @@ class ShellModule(object):
basetmp = self.join_path(C.DEFAULT_REMOTE_TMP, basefile) basetmp = self.join_path(C.DEFAULT_REMOTE_TMP, basefile)
if system and (basetmp.startswith('$HOME') or basetmp.startswith('~/')): if system and (basetmp.startswith('$HOME') or basetmp.startswith('~/')):
basetmp = self.join_path('/tmp', basefile) basetmp = self.join_path('/tmp', basefile)
cmd = 'mkdir -p %s' % basetmp cmd = 'mkdir -p "%s"' % basetmp
if mode: if mode:
cmd += ' && chmod %s %s' % (mode, basetmp) cmd += ' && chmod %s "%s"' % (mode, basetmp)
cmd += ' && echo %s' % basetmp cmd += ' && echo "%s"' % basetmp
return cmd return cmd
def expand_user(self, user_home_path): def expand_user(self, user_home_path):
@ -127,8 +127,12 @@ class ShellModule(object):
return cmd return cmd
def build_module_command(self, env_string, shebang, cmd, rm_tmp=None): def build_module_command(self, env_string, shebang, cmd, rm_tmp=None):
# don't quote the cmd if it's an empty string, because this will
# break pipelining mode
if cmd.strip() != '':
cmd = pipes.quote(cmd)
cmd_parts = [env_string.strip(), shebang.replace("#!", "").strip(), cmd] cmd_parts = [env_string.strip(), shebang.replace("#!", "").strip(), cmd]
new_cmd = " ".join(cmd_parts) new_cmd = " ".join(cmd_parts)
if rm_tmp: if rm_tmp:
new_cmd = '%s; rm -rf %s >/dev/null 2>&1' % (new_cmd, rm_tmp) new_cmd = '%s; rm -rf "%s" >/dev/null 2>&1' % (new_cmd, rm_tmp)
return new_cmd return new_cmd