Fixes/notes related to slashes in remote paths.

pull/7861/head
Chris Church 10 years ago committed by Matt Martz
parent 4991c77479
commit 21ba529fbe

@ -136,8 +136,8 @@ class ActionModule(object):
# If it's recursive copy, destination is always a dir, # If it's recursive copy, destination is always a dir,
# explicitly mark it so (note - copy module relies on this). # explicitly mark it so (note - copy module relies on this).
if not dest.endswith("/"): if not conn.shell.path_has_trailing_slash(dest):
dest += "/" dest = conn.shell.join_path(dest, '')
else: else:
source_files.append((source, os.path.basename(source))) source_files.append((source, os.path.basename(source)))
@ -169,10 +169,10 @@ class ActionModule(object):
# This is kind of optimization - if user told us destination is # This is kind of optimization - if user told us destination is
# dir, do path manipulation right away, otherwise we still check # dir, do path manipulation right away, otherwise we still check
# for dest being a dir via remote call below. # for dest being a dir via remote call below.
if dest.endswith("/"): # CCTODO: Fixme for powershell if conn.shell.path_has_trailing_slash(dest):
dest_file = os.path.join(dest, source_rel) dest_file = conn.shell.join_path(dest, source_rel)
else: else:
dest_file = dest dest_file = conn.shell.join_path(dest)
# Attempt to get the remote MD5 Hash. # Attempt to get the remote MD5 Hash.
remote_md5 = self.runner._remote_md5(conn, tmp_path, dest_file) remote_md5 = self.runner._remote_md5(conn, tmp_path, dest_file)
@ -186,7 +186,7 @@ class ActionModule(object):
return ReturnData(conn=conn, result=result) return ReturnData(conn=conn, result=result)
else: else:
# Append the relative source location to the destination and retry remote_md5. # Append the relative source location to the destination and retry remote_md5.
dest_file = os.path.join(dest, source_rel) # CCTODO dest_file = conn.shell.join_path(dest, source_rel)
remote_md5 = self.runner._remote_md5(conn, tmp_path, dest_file) remote_md5 = self.runner._remote_md5(conn, tmp_path, dest_file)
if remote_md5 != '1' and not force: if remote_md5 != '1' and not force:

@ -59,7 +59,7 @@ class ActionModule(object):
source = os.path.expanduser(source) source = os.path.expanduser(source)
if flat: if flat:
if dest.endswith("/"): # CCTODO if dest.endswith("/"): # CCTODO: Fix path for Windows hosts.
# if the path ends with "/", we'll use the source filename as the # if the path ends with "/", we'll use the source filename as the
# destination filename # destination filename
base = os.path.basename(source) base = os.path.basename(source)

@ -79,7 +79,7 @@ class ActionModule(object):
source = utils.path_dwim(self.runner.basedir, source) source = utils.path_dwim(self.runner.basedir, source)
if dest.endswith("/"): # CCTODO if dest.endswith("/"): # CCTODO: Fix path for Windows hosts.
base = os.path.basename(source) base = os.path.basename(source)
dest = os.path.join(dest, base) dest = os.path.join(dest, base)

@ -54,7 +54,7 @@ class ActionModule(object):
result = dict(failed=True, msg="src (or content) and dest are required") result = dict(failed=True, msg="src (or content) and dest are required")
return ReturnData(conn=conn, result=result) return ReturnData(conn=conn, result=result)
dest = os.path.expanduser(dest) dest = os.path.expanduser(dest) # CCTODO: Fix path for Windows hosts.
source = template.template(self.runner.basedir, os.path.expanduser(source), inject) source = template.template(self.runner.basedir, os.path.expanduser(source), inject)
if copy: if copy:
if '_original_file' in inject: if '_original_file' in inject:

@ -58,6 +58,10 @@ class ShellModule(object):
def join_path(self, *args): def join_path(self, *args):
return os.path.join(*args).replace('/', '\\') return os.path.join(*args).replace('/', '\\')
def path_has_trailing_slash(self, path):
# Allow Windows paths to be specified using either slash.
return path.endswith('/') or path.endswith('\\')
def chmod(self, mode, path): def chmod(self, mode, path):
return '' return ''

@ -33,6 +33,9 @@ class ShellModule(object):
def join_path(self, *args): def join_path(self, *args):
return os.path.join(*args) return os.path.join(*args)
def path_has_trailing_slash(self, path):
return path.endswith('/')
def chmod(self, mode, path): def chmod(self, mode, path):
path = pipes.quote(path) path = pipes.quote(path)
return 'chmod %s %s' % (mode, path) return 'chmod %s %s' % (mode, path)

Loading…
Cancel
Save