Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_copy: Add missing check_mode fix #31469

Merged
merged 2 commits into from
Oct 9, 2017
Merged

win_copy: Add missing check_mode fix #31469

merged 2 commits into from
Oct 9, 2017

Conversation

vtsingaras
Copy link
Contributor

@vtsingaras vtsingaras commented Oct 9, 2017

SUMMARY

win_copy would remove the destination file if it existed even when running with check_mode: yes

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

win_copy

ANSIBLE VERSION

2.4.0

@ansibot
Copy link
Contributor

ansibot commented Oct 9, 2017

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bugfix_pull_request core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community labels Oct 9, 2017
@dagwieers dagwieers changed the title Add missing check_mode fix win_copy: Add missing check_mode fix Oct 9, 2017
@@ -76,7 +76,9 @@ Function Copy-File($source, $dest) {
}

if (Test-Path -Path $dest -PathType Leaf) {
Remove-Item -Path $dest -Force -Recurse | Out-Null
if (-not $check_mode) {
Remove-Item -Path $dest -Force -Recurse | Out-Null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply do:

Remove-Item -Path $dest -Force -Recurse -WhatIf:$check_mode | Out-Null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, got miscarried by earlier comments that avoided WhatIf because the path didn't exist; which is not the case here as the if conditional is Test-Path.... (facepalm)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. In reality there won't be a real difference, on the other hand if Microsoft at some point improves Remove-Item to also detect other failure-cases (in a safe way) the -WhatIf implementation may prove to be more useful.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. labels Oct 9, 2017
@dagwieers
Copy link
Contributor

If Shippable likes it, I will merge this. Thanks !

@dagwieers dagwieers merged commit 5bf9f27 into ansible:devel Oct 9, 2017
jborean93 pushed a commit that referenced this pull request Oct 9, 2017
* Add missing check_mode fix

* Refactor conditional to use the one embedded in Remove-Item

(cherry picked from commit 5bf9f27)
@jborean93
Copy link
Contributor

Thanks for the fix @vtsingaras, I have cherry-picked this commit to stable-2.4 https://github.com/ansible/ansible/commits/stable-2.4 for the 2.4.1 release.

@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants