mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-12 03:09:32 -07:00
fix Ansible.ModuleUtils.FileUtil to respect ErrorAction if running in a try/catch (#45451)
This commit is contained in:
parent
c9c141fb6a
commit
d4ce1b9f31
2 changed files with 18 additions and 1 deletions
|
@ -38,7 +38,16 @@ Function Get-AnsibleItem {
|
|||
[Parameter(Mandatory=$true)][string]$Path
|
||||
)
|
||||
# Replacement for Get-Item
|
||||
$file_attributes = [System.IO.File]::GetAttributes($Path)
|
||||
try {
|
||||
$file_attributes = [System.IO.File]::GetAttributes($Path)
|
||||
} catch {
|
||||
# if -ErrorAction SilentlyCotinue is set on the cmdlet and we failed to
|
||||
# get the attributes, just return $null, otherwise throw the error
|
||||
if ($ErrorActionPreference -ne "SilentlyContinue") {
|
||||
throw $_
|
||||
}
|
||||
return $null
|
||||
}
|
||||
if ([Int32]$file_attributes -eq -1) {
|
||||
throw New-Object -TypeName System.Management.Automation.ItemNotFoundException -ArgumentList "Cannot find path '$Path' because it does not exist."
|
||||
} elseif ($file_attributes.HasFlag([System.IO.FileAttributes]::Directory)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue