mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_file: Fix check-mode issue removing dirs (#30475)
This fixed #30442
This commit is contained in:
parent
1062f52f4c
commit
229a86c952
1 changed files with 11 additions and 22 deletions
|
@ -1,21 +1,10 @@
|
||||||
#!powershell
|
#!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
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# POWERSHELL_COMMON
|
|
||||||
|
# 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"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
@ -61,7 +50,7 @@ function Remove-File($file, $checkmode) {
|
||||||
[Ansible.Command.SymLinkHelper]::DeleteSymLink($file.FullName)
|
[Ansible.Command.SymLinkHelper]::DeleteSymLink($file.FullName)
|
||||||
}
|
}
|
||||||
} elseif ($file.PSIsContainer) {
|
} elseif ($file.PSIsContainer) {
|
||||||
Remove-Directory -directory $file -WhatIf:$checkmode
|
Remove-Directory -directory $file -checkmode $checkmode
|
||||||
} else {
|
} else {
|
||||||
Remove-Item -Path $file.FullName -Force -WhatIf:$checkmode
|
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) {
|
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
|
$fileinfo = Get-Item -Path $path
|
||||||
if ($state -eq "absent") {
|
if ($state -eq "absent") {
|
||||||
Remove-File -File $fileinfo -CheckMode $check_mode
|
Remove-File -file $fileinfo -checkmode $check_mode
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
} else {
|
} else {
|
||||||
if ($state -eq "directory" -and -not $fileinfo.PsIsContainer) {
|
if ($state -eq "directory" -and -not $fileinfo.PsIsContainer) {
|
||||||
|
|
Loading…
Reference in a new issue