From 92b3c3a65ba8da8d43ee4081bf92ea473e0e2d30 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 19 Mar 2019 09:20:33 +1000 Subject: [PATCH] win_file - fix glob like paths (#54003) (cherry picked from commit c053bc1fc7dd351bf5039c03776cab662a112107) --- changelogs/fragments/win_file-paths.yaml | 2 ++ lib/ansible/modules/windows/win_file.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/win_file-paths.yaml diff --git a/changelogs/fragments/win_file-paths.yaml b/changelogs/fragments/win_file-paths.yaml new file mode 100644 index 00000000000..bf260f0b949 --- /dev/null +++ b/changelogs/fragments/win_file-paths.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_file - Fix issues when using paths with glob like characters, e.g. ``[``, ``]`` diff --git a/lib/ansible/modules/windows/win_file.ps1 b/lib/ansible/modules/windows/win_file.ps1 index c841de1315b..9c35b0c747b 100644 --- a/lib/ansible/modules/windows/win_file.ps1 +++ b/lib/ansible/modules/windows/win_file.ps1 @@ -18,7 +18,7 @@ $state = Get-AnsibleParam -obj $params -name "state" -type "str" -validateset "a # used in template/copy when dest is the path to a dir and source is a file $original_basename = Get-AnsibleParam -obj $params -name "_original_basename" -type "str" -if ((Test-Path -Path $path -PathType Container) -and ($null -ne $original_basename)) { +if ((Test-Path -LiteralPath $path -PathType Container) -and ($null -ne $original_basename)) { $path = Join-Path -Path $path -ChildPath $original_basename } @@ -86,7 +86,7 @@ function Remove-File($file, $checkmode) { } function Remove-Directory($directory, $checkmode) { - foreach ($file in Get-ChildItem $directory.FullName) { + foreach ($file in Get-ChildItem -LiteralPath $directory.FullName) { Remove-File -file $file -checkmode $checkmode } Remove-Item -LiteralPath $directory.FullName -Force -Recurse -WhatIf:$checkmode