Revised following comments from Chris Church.

Now uses sha1 checksums following merge of 9688.
Also I undid the changes I made to fetch.py
win_template.py now uses conn.shell.has_trailing_slash and
conn.shell.join_path
updated integration tests.
pull/9611/head
Jon Hawkesworth 10 years ago
parent bf916fb58a
commit e37b63386c

@ -142,14 +142,14 @@ Function ConvertTo-Bool
return return
} }
# Helper function to calculate md5 of a file in a way which powershell 3 # Helper function to calculate a hash of a file in a way which powershell 3
# and above can handle: # and above can handle:
Function Get-FileMd5($path) Function Get-FileChecksum($path)
{ {
$hash = "" $hash = ""
If (Test-Path -PathType Leaf $path) If (Test-Path -PathType Leaf $path)
{ {
$sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider; $sp = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider;
$fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read); $fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
[System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower(); [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
$fp.Dispose(); $fp.Dispose();

@ -127,13 +127,13 @@ class ActionModule(object):
elif remote_checksum == '2': elif remote_checksum == '2':
result = dict(msg="no read permission on remote file, not transferring, ignored", file=source, changed=False) result = dict(msg="no read permission on remote file, not transferring, ignored", file=source, changed=False)
elif remote_checksum == '3': elif remote_checksum == '3':
result = dict(failed=True, msg="remote file is a directory, fetch cannot work on directories", file=source, changed=False) result = dict(msg="remote file is a directory, fetch cannot work on directories", file=source, changed=False)
elif remote_checksum == '4': elif remote_checksum == '4':
result = dict(msg="python isn't present on the system. Unable to compute checksum", file=source, changed=False) result = dict(msg="python isn't present on the system. Unable to compute checksum", file=source, changed=False)
return ReturnData(conn=conn, result=result) return ReturnData(conn=conn, result=result)
# calculate checksum for the local file # calculate checksum for the local file
local_checksum = utils.md5(dest) local_checksum = utils.checksum(dest)
if remote_checksum != local_checksum: if remote_checksum != local_checksum:
# create the containing directories, if needed # create the containing directories, if needed
@ -147,8 +147,7 @@ class ActionModule(object):
f = open(dest, 'w') f = open(dest, 'w')
f.write(remote_data) f.write(remote_data)
f.close() f.close()
new_checksum = utils.md5(dest) new_checksum = utils.secure_hash(dest)
# new_checksum = utils.secure_hash(dest)
# For backwards compatibility. We'll return None on FIPS enabled # For backwards compatibility. We'll return None on FIPS enabled
# systems # systems
try: try:

@ -75,10 +75,9 @@ class ActionModule(object):
else: else:
source = utils.path_dwim(self.runner.basedir, source) source = utils.path_dwim(self.runner.basedir, source)
if conn.shell.path_has_trailing_slash(dest):
if dest.endswith("\\"): # TODO: Check that this fixes the path for Windows hosts.
base = os.path.basename(source) base = os.path.basename(source)
dest = os.path.join(dest, base) dest = conn.shell.join_path(dest, base)
# template the source data locally & get ready to transfer # template the source data locally & get ready to transfer
try: try:

@ -62,12 +62,14 @@
- name: verify that the file checksum is correct - name: verify that the file checksum is correct
assert: assert:
that: that:
- "copy_result.checksum[0] == 'c47397529fe81ab62ba3f85e9f4c71f2'" - "copy_result.checksum[0] == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'"
- name: check the stat results of the file - name: check the stat results of the file
win_stat: path={{output_file}} win_stat: path={{output_file}}
register: stat_results register: stat_results
- debug: var=stat_results
- name: assert the stat results are correct - name: assert the stat results are correct
assert: assert:
that: that:
@ -76,7 +78,7 @@
# - "stat_results.stat.isfifo == false" # - "stat_results.stat.isfifo == false"
# - "stat_results.stat.isreg == true" # - "stat_results.stat.isreg == true"
# - "stat_results.stat.issock == false" # - "stat_results.stat.issock == false"
- "stat_results.stat.md5[0] == 'c47397529fe81ab62ba3f85e9f4c71f2'" - "stat_results.stat.checksum[0] == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'"
- name: overwrite the file via same means - name: overwrite the file via same means
win_copy: src=foo.txt dest={{output_file}} win_copy: src=foo.txt dest={{output_file}}

Loading…
Cancel
Save