mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-04 23:44:00 -07:00
windows - Fix module utils with glob paths (#53835)
* windows - Fix module utils with glob paths * fix link util tests when using DOS 8.3 paths
This commit is contained in:
parent
a6a4e82984
commit
980ca564ce
7 changed files with 45 additions and 26 deletions
|
@ -46,12 +46,12 @@ Function Get-ExecutablePath {
|
|||
$full_path = [System.IO.Path]::GetFullPath($executable)
|
||||
|
||||
if ($full_path -ne $executable -and $directory -ne $null) {
|
||||
$file = Get-Item -Path "$directory\$executable" -Force -ErrorAction SilentlyContinue
|
||||
$file = Get-Item -LiteralPath "$directory\$executable" -Force -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
$file = Get-Item -Path $executable -Force -ErrorAction SilentlyContinue
|
||||
$file = Get-Item -LiteralPath $executable -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if ($file -ne $null) {
|
||||
if ($null -ne $file) {
|
||||
$executable_path = $file.FullName
|
||||
} else {
|
||||
$executable_path = [Ansible.Process.ProcessUtil]::SearchPath($executable)
|
||||
|
@ -93,7 +93,7 @@ Function Run-Command {
|
|||
# need to validate the working directory if it is set
|
||||
if ($working_directory) {
|
||||
# validate working directory is a valid path
|
||||
if (-not (Test-Path -Path $working_directory)) {
|
||||
if (-not (Test-Path -LiteralPath $working_directory)) {
|
||||
throw "invalid working directory path '$working_directory'"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ Function Get-FileChecksum($path, $algorithm = 'sha1')
|
|||
Helper function to calculate a hash of a file in a way which PowerShell 3
|
||||
and above can handle
|
||||
#>
|
||||
If (Test-Path -Path $path -PathType Leaf)
|
||||
If (Test-Path -LiteralPath $path -PathType Leaf)
|
||||
{
|
||||
switch ($algorithm)
|
||||
{
|
||||
|
@ -334,7 +334,7 @@ Function Get-FileChecksum($path, $algorithm = 'sha1')
|
|||
}
|
||||
|
||||
If ($PSVersionTable.PSVersion.Major -ge 4) {
|
||||
$raw_hash = Get-FileHash $path -Algorithm $algorithm
|
||||
$raw_hash = Get-FileHash -LiteralPath $path -Algorithm $algorithm
|
||||
$hash = $raw_hash.Hash.ToLower()
|
||||
} Else {
|
||||
$fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite);
|
||||
|
@ -342,7 +342,7 @@ Function Get-FileChecksum($path, $algorithm = 'sha1')
|
|||
$fp.Dispose();
|
||||
}
|
||||
}
|
||||
ElseIf (Test-Path -Path $path -PathType Container)
|
||||
ElseIf (Test-Path -LiteralPath $path -PathType Container)
|
||||
{
|
||||
$hash = "3";
|
||||
}
|
||||
|
|
|
@ -425,7 +425,7 @@ Function Remove-Link($link_path) {
|
|||
}
|
||||
|
||||
Function New-Link($link_path, $link_target, $link_type) {
|
||||
if (-not (Test-Path -Path $link_target)) {
|
||||
if (-not (Test-Path -LiteralPath $link_target)) {
|
||||
throw "link_target '$link_target' does not exist, cannot create link"
|
||||
}
|
||||
|
||||
|
@ -434,13 +434,13 @@ Function New-Link($link_path, $link_target, $link_type) {
|
|||
$type = [Ansible.LinkType]::SymbolicLink
|
||||
}
|
||||
"junction" {
|
||||
if (Test-Path -Path $link_target -PathType Leaf) {
|
||||
if (Test-Path -LiteralPath $link_target -PathType Leaf) {
|
||||
throw "cannot set the target for a junction point to a file"
|
||||
}
|
||||
$type = [Ansible.LinkType]::JunctionPoint
|
||||
}
|
||||
"hard" {
|
||||
if (Test-Path -Path $link_target -PathType Container) {
|
||||
if (Test-Path -LiteralPath $link_target -PathType Container) {
|
||||
throw "cannot set the target for a hard link to a directory"
|
||||
}
|
||||
$type = [Ansible.LinkType]::HardLink
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue