Ansible.ModuleUtils.FileUtil - backport catch DirectoryNotFoundException (#37976)

* Ansible.ModuleUtils.FileUtil: catch DirectoryNotFoundException when testing a path (#37968)

(cherry picked from commit 68e44e082e)

* Added changelog fragments
pull/38238/head
Jordan Borean 7 years ago committed by GitHub
parent f1a060743a
commit d0f1a23c45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- Ansible.ModuleUtils.FileUtil - Catch DirectoryNotFoundException with Test-AnsiblePath
https://github.com/ansible/ansible/pull/37968

@ -17,7 +17,7 @@ Function Test-AnsiblePath {
# Replacement for Test-Path
try {
$file_attributes = [System.IO.File]::GetAttributes($Path)
} catch [System.IO.FileNotFoundException] {
} catch [System.IO.FileNotFoundException], [System.IO.DirectoryNotFoundException] {
return $false
}

@ -48,6 +48,14 @@ if ($pagefile) {
$actual = Test-AnsiblePath -Path C:\fakefile
Assert-Equals -actual $actual -expected $false
# Test-AnsiblePath Directory that doesn't exist
$actual = Test-AnsiblePath -Path C:\fakedirectory
Assert-Equals -actual $actual -expected $false
# Test-AnsiblePath file in non-existant directory
$actual = Test-AnsiblePath -Path C:\fakedirectory\fakefile.txt
Assert-Equals -actual $actual -expected $false
# Test-AnsiblePath Normal directory
$actual = Test-AnsiblePath -Path C:\Windows
Assert-Equals -actual $actual -expected $true

@ -144,6 +144,19 @@
that:
- statout.stat.exists == true
# https://github.com/ansible/ansible/issues/37967
- name: test creates with file in missing directory
win_shell: echo hi
args:
creates: c:\fakefolder\fakefolder2\fakefile.txt
register: shellout
- name: validate result
assert:
that:
- shellout.skipped is not defined
- shellout.changed
- name: run with removes, should remove
win_shell: Remove-Item c:\testfile.txt
args:

Loading…
Cancel
Save