summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag Wieers <dag@wieers.com>2017-09-18 22:43:49 +0200
committerjborean93 <jborean93@gmail.com>2017-09-19 06:49:45 +1000
commitf1f8d0319fc3e01a377065ac1e7b916960bb67d5 (patch)
tree5f306bda011687a746a6b50034cf3f4f383c2cbb
parent4f5bf2e08fbbaa0497d54ef08442b80d1c49a021 (diff)
downloadansible-f1f8d0319fc3e01a377065ac1e7b916960bb67d5.tar.gz
win_file: Fix check-mode issue removing dirs (#30475)
This fixed #30442 (cherry picked from commit 229a86c952a32821962668c1da68a46f0b9bb711)
-rw-r--r--lib/ansible/modules/windows/win_file.ps135
1 files changed, 12 insertions, 23 deletions
diff --git a/lib/ansible/modules/windows/win_file.ps1 b/lib/ansible/modules/windows/win_file.ps1
index 4e6933923c..9f62180c25 100644
--- a/lib/ansible/modules/windows/win_file.ps1
+++ b/lib/ansible/modules/windows/win_file.ps1
@@ -1,21 +1,10 @@
#!powershell
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-
-# WANT_JSON
-# POWERSHELL_COMMON
+
+# Copyright: (c) 2017, Ansible Project
+
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+#Requires -Module Ansible.ModuleUtils.Legacy.psm1
$ErrorActionPreference = "Stop"
@@ -61,7 +50,7 @@ function Remove-File($file, $checkmode) {
[Ansible.Command.SymLinkHelper]::DeleteSymLink($file.FullName)
}
} elseif ($file.PSIsContainer) {
- Remove-Directory -directory $file -WhatIf:$checkmode
+ Remove-Directory -directory $file -checkmode $checkmode
} else {
Remove-Item -Path $file.FullName -Force -WhatIf:$checkmode
}
@@ -70,11 +59,11 @@ function Remove-File($file, $checkmode) {
}
}
-function Remove-Directory($directory) {
+function Remove-Directory($directory, $checkmode) {
foreach ($file in Get-ChildItem $directory.FullName) {
- Remove-File -file $file
+ Remove-File -file $file -checkmode $checkmode
}
- Remove-Item -Path $directory.FullName -Force -Recurse
+ Remove-Item -Path $directory.FullName -Force -Recurse -WhatIf:$checkmode
}
@@ -87,10 +76,10 @@ if ($state -eq "touch") {
}
}
-if (Test-Path $path) {
+if (Test-Path -Path $path) {
$fileinfo = Get-Item -Path $path
if ($state -eq "absent") {
- Remove-File -File $fileinfo -CheckMode $check_mode
+ Remove-File -file $fileinfo -checkmode $check_mode
$result.changed = $true
} else {
if ($state -eq "directory" -and -not $fileinfo.PsIsContainer) {