win_copy: Fix for idempotency (#20281)

* include source file in error message

* win_copy: Fix for idempotency

This patch fixes an idempotency issue with win_copy. Without this patch
files would always be considered changed (unless the copy operation failed).

It also fixes the resulting output cfr. what was deocumented.
pull/20566/merge
Dag Wieers 8 years ago committed by John R Barker
parent c950767898
commit ce2284a793

@ -60,10 +60,10 @@ if (Test-Path $dest -PathType Container)
$dest = Join-Path $dest $original_basename
}
$dest_checksum = Get-FileChecksum ($dest)
$orig_checksum = Get-FileChecksum ($dest)
$src_checksum = Get-FileChecksum ($src)
If ($src_checksum.Equals($dest_checksum))
If ($src_checksum.Equals($orig_checksum))
{
# if both are "3" then both are folders, ok to copy
If ($src_checksum.Equals("3"))
@ -75,7 +75,7 @@ If ($src_checksum.Equals($dest_checksum))
}
}
ElseIf (! $src_checksum.Equals($dest_checksum))
ElseIf (-Not $src_checksum.Equals($orig_checksum))
{
If ($src_checksum.Equals("3"))
{
@ -88,17 +88,20 @@ ElseIf (! $src_checksum.Equals($dest_checksum))
# verify before we return that the file has changed
$dest_checksum = Get-FileChecksum ($dest)
If ( $src_checksum.Equals($dest_checksum))
If ($src_checksum.Equals($dest_checksum))
{
$result.changed = $TRUE
If (-Not $orig_checksum.Equals($dest_checksum)) {
$result.changed = $TRUE
}
}
Else
{
Fail-Json (New-Object psobject) "src checksum $src_checksum did not match dest_checksum $dest_checksum Failed to place file $original_basename in $dest"
}
# generate return values
$info = Get-Item $dest
$result.size = $info.Length
$result.src = $src
$result.dest = $dest
Exit-Json $result

@ -38,15 +38,12 @@ options:
with "/", only inside contents of that directory are copied to destination.
Otherwise, if it does not end with "/", the directory itself with all contents
is copied. This behavior is similar to Rsync.
required: false
default: null
aliases: []
required: true
dest:
description:
- Remote absolute path where the file should be copied to. If src is a directory,
this must be a directory too. Use \\ for path separators.
required: true
default: null
author: "Jon Hawkesworth (@jhawkesworth)"
'''
@ -54,19 +51,19 @@ EXAMPLES = r'''
- name: Copy a single file
win_copy:
src: /srv/myfiles/foo.conf
dest: c:\TEMP\foo.conf
dest: c:\Temp\foo.conf
- name: Copy files/temp_files to c:\temp
win_copy:
src: files/temp_files/
dest: c:\temp
dest: c:\Temp
'''
RETURN = r'''
dest:
description: destination file/path
returned: changed
type: string
sample: c:\temp
sample: c:\Temp
src:
description: source file used for the copy on the target machine
returned: changed

Loading…
Cancel
Save