mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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.
This commit is contained in:
parent
bf916fb58a
commit
e37b63386c
4 changed files with 12 additions and 12 deletions
|
@ -142,14 +142,14 @@ Function ConvertTo-Bool
|
|||
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:
|
||||
Function Get-FileMd5($path)
|
||||
Function Get-FileChecksum($path)
|
||||
{
|
||||
$hash = ""
|
||||
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);
|
||||
[System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
|
||||
$fp.Dispose();
|
||||
|
|
|
@ -127,13 +127,13 @@ class ActionModule(object):
|
|||
elif remote_checksum == '2':
|
||||
result = dict(msg="no read permission on remote file, not transferring, ignored", file=source, changed=False)
|
||||
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':
|
||||
result = dict(msg="python isn't present on the system. Unable to compute checksum", file=source, changed=False)
|
||||
return ReturnData(conn=conn, result=result)
|
||||
|
||||
# calculate checksum for the local file
|
||||
local_checksum = utils.md5(dest)
|
||||
local_checksum = utils.checksum(dest)
|
||||
|
||||
if remote_checksum != local_checksum:
|
||||
# create the containing directories, if needed
|
||||
|
@ -147,8 +147,7 @@ class ActionModule(object):
|
|||
f = open(dest, 'w')
|
||||
f.write(remote_data)
|
||||
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
|
||||
# systems
|
||||
try:
|
||||
|
|
|
@ -75,10 +75,9 @@ class ActionModule(object):
|
|||
else:
|
||||
source = utils.path_dwim(self.runner.basedir, source)
|
||||
|
||||
|
||||
if dest.endswith("\\"): # TODO: Check that this fixes the path for Windows hosts.
|
||||
if conn.shell.path_has_trailing_slash(dest):
|
||||
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
|
||||
try:
|
||||
|
|
|
@ -62,12 +62,14 @@
|
|||
- name: verify that the file checksum is correct
|
||||
assert:
|
||||
that:
|
||||
- "copy_result.checksum[0] == 'c47397529fe81ab62ba3f85e9f4c71f2'"
|
||||
- "copy_result.checksum[0] == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'"
|
||||
|
||||
- name: check the stat results of the file
|
||||
win_stat: path={{output_file}}
|
||||
register: stat_results
|
||||
|
||||
- debug: var=stat_results
|
||||
|
||||
- name: assert the stat results are correct
|
||||
assert:
|
||||
that:
|
||||
|
@ -76,7 +78,7 @@
|
|||
# - "stat_results.stat.isfifo == false"
|
||||
# - "stat_results.stat.isreg == true"
|
||||
# - "stat_results.stat.issock == false"
|
||||
- "stat_results.stat.md5[0] == 'c47397529fe81ab62ba3f85e9f4c71f2'"
|
||||
- "stat_results.stat.checksum[0] == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'"
|
||||
|
||||
- name: overwrite the file via same means
|
||||
win_copy: src=foo.txt dest={{output_file}}
|
||||
|
|
Loading…
Reference in a new issue