Add directory detection to _remote_md5 and use this in copy
If it is a directory, change the destination path by appending the basename of the source file, like is done if the destination ends with a /, and try to get the MD5 of the new path.
This commit is contained in:
parent
f12dbd431a
commit
7e2999ed2d
2 changed files with 9 additions and 5 deletions
|
@ -511,7 +511,7 @@ class Runner(object):
|
||||||
def _remote_md5(self, conn, tmp, path):
|
def _remote_md5(self, conn, tmp, path):
|
||||||
''' takes a remote md5sum without requiring python, and returns 0 if no file '''
|
''' takes a remote md5sum without requiring python, and returns 0 if no file '''
|
||||||
|
|
||||||
test = "rc=0; [ -r \"%s\" ] || rc=2; [ -f \"%s\" ] || rc=1" % (path,path)
|
test = "rc=0; [ -r \"%s\" ] || rc=2; [ -f \"%s\" ] || rc=1; [ -d \"%s\" ] && rc=3" % (path, path, path)
|
||||||
md5s = [
|
md5s = [
|
||||||
"(/usr/bin/md5sum %s 2>/dev/null)" % path, # Linux
|
"(/usr/bin/md5sum %s 2>/dev/null)" % path, # Linux
|
||||||
"(/sbin/md5sum -q %s 2>/dev/null)" % path, # ?
|
"(/sbin/md5sum -q %s 2>/dev/null)" % path, # ?
|
||||||
|
|
|
@ -34,10 +34,6 @@ class ActionModule(object):
|
||||||
source = options.get('src', None)
|
source = options.get('src', None)
|
||||||
dest = options.get('dest', None)
|
dest = options.get('dest', None)
|
||||||
|
|
||||||
if dest.endswith("/"):
|
|
||||||
base = os.path.basename(source)
|
|
||||||
dest = os.path.join(dest, base)
|
|
||||||
|
|
||||||
if (source is None and not 'first_available_file' in inject) or dest is None:
|
if (source is None and not 'first_available_file' in inject) or dest is None:
|
||||||
result=dict(failed=True, msg="src and dest are required")
|
result=dict(failed=True, msg="src and dest are required")
|
||||||
return ReturnData(conn=conn, result=result)
|
return ReturnData(conn=conn, result=result)
|
||||||
|
@ -65,7 +61,15 @@ class ActionModule(object):
|
||||||
result=dict(failed=True, msg="could not find src=%s" % source)
|
result=dict(failed=True, msg="could not find src=%s" % source)
|
||||||
return ReturnData(conn=conn, result=result)
|
return ReturnData(conn=conn, result=result)
|
||||||
|
|
||||||
|
if dest.endswith("/"):
|
||||||
|
base = os.path.basename(source)
|
||||||
|
dest = os.path.join(dest, base)
|
||||||
|
|
||||||
remote_md5 = self.runner._remote_md5(conn, tmp, dest)
|
remote_md5 = self.runner._remote_md5(conn, tmp, dest)
|
||||||
|
if remote_md5 == '3':
|
||||||
|
# Destination is a directory
|
||||||
|
dest = os.path.join(dest, os.path.basename(source))
|
||||||
|
remote_md5 = self.runner._remote_md5(conn, tmp, dest)
|
||||||
|
|
||||||
exec_rc = None
|
exec_rc = None
|
||||||
if local_md5 != remote_md5:
|
if local_md5 != remote_md5:
|
||||||
|
|
Loading…
Reference in a new issue