a copy of the pull request from ansible/ansible-modules-extras#3515 by @twistyWater

This fixes #19959 - exception throw when robocopy return_code is not 1 2 or 4.
This commit is contained in:
Scott Sinclair 2017-01-07 18:21:57 +11:00
parent cba66dfedc
commit de5d08a786

View file

@ -115,34 +115,55 @@ Set-Attr $result.win_robocopy "return_code" $rc
Set-Attr $result.win_robocopy "output" $robocopy_output Set-Attr $result.win_robocopy "output" $robocopy_output
$cmd_msg = "Success" $cmd_msg = "Success"
If ($rc -eq 0) { $changed = $false
$cmd_msg = "No files copied." switch ($rc)
} {
ElseIf ($rc -eq 1) { 0 {
$cmd_msg = "Files copied successfully!" $cmd_msg = "No files copied."
$changed = $true }
} 1 {
ElseIf ($rc -eq 2) { $cmd_msg = "Files copied successfully!"
$cmd_msg = "Extra files or directories were detected!" $changed = $true
$changed = $true }
} 2 {
ElseIf ($rc -eq 4) { $cmd_msg = "Some Extra files or directories were detected. No files were copied."
$cmd_msg = "Some mismatched files or directories were detected!" $changed = $true
$changed = $true }
} 3 {
ElseIf ($rc -eq 8) { $cmd_msg = "(2+1) Some files were copied. Additional files were present."
$error_msg = SearchForError $robocopy_output "Some files or directories could not be copied!" $changed = $true
Fail-Json $result $error_msg }
} 4 {
ElseIf ($rc -eq 10) { $cmd_msg = "Some mismatched files or directories were detected. Housekeeping might be required!"
$error_msg = SearchForError $robocopy_output "Serious Error! No files were copied! Do you have permissions to access $src and $dest?" $changed = $true
Fail-Json $result $error_msg }
} 5 {
ElseIf ($rc -eq 16) { $cmd_msg = "(4+1) Some files were copied. Some files were mismatched."
$error_msg = SearchForError $robocopy_output "Fatal Error!" $changed = $true
Fail-Json $result $error_msg }
6 {
$cmd_msg = "(4+2) Additional files and mismatched files exist. No files were copied."
$changed = $true
}
7 {
$cmd_msg = "(4+1+2) Files were copied, a file mismatch was present, and additional files were present."
$changed = $true
}
8 {
$error_msg = SearchForError $robocopy_output "Some files or directories could not be copied!"
Fail-Json $result $error_msg
}
{ @(9, 10, 11, 12, 13, 14, 15) -contains $_ } {
$error_msg = SearchForError $robocopy_output "Fatal error. Check log message!"
Fail-Json $result $error_msg
}
16 {
$error_msg = SearchForError $robocopy_output "Serious Error! No files were copied! Do you have permissions to access $src and $dest?"
Fail-Json $result $error_msg
}
} }
Set-Attr $result.win_robocopy "msg" $cmd_msg Set-Attr $result.win_robocopy "msg" $cmd_msg
Set-Attr $result.win_robocopy "changed" $changed Set-Attr $result.win_robocopy "changed" $changed