win_stat change return islink to islnk to match stat (#23196)

This commit is contained in:
Jordan Borean 2017-04-04 04:38:34 +10:00 committed by Matt Davis
parent 5918bebd6e
commit 4d1b97d1ae
5 changed files with 317 additions and 427 deletions

View file

@ -69,22 +69,6 @@ function Date_To_Timestamp($start_date, $end_date)
}
}
function Get-Hash($path, $algorithm) {
# Using PowerShell V4 and above we can use some powershell cmdlets instead of .net
If ($PSVersionTable.PSVersion.Major -ge 4)
{
$hash = (Get-FileHash -Path $path -Algorithm $algorithm).Hash
}
Else
{
$net_algorithm = [Security.Cryptography.HashAlgorithm]::Create($algorithm)
$raw_hash = [System.BitConverter]::ToString($net_algorithm.ComputeHash([System.IO.File]::ReadAllBytes($path)))
$hash = $raw_hash -replace '-'
}
$hash.ToLower()
}
$params = Parse-Args $args -supports_check_mode $true
$path = Get-AnsibleParam -obj $params -name "path" -type "path" -failifempty $true -aliases "dest","name"
@ -95,7 +79,7 @@ $checksum_algorithm = Get-AnsibleParam -obj $params -name "checksum_algorithm" -
$result = @{
changed = $false
stat = @{}
};
}
# Backward compatibility
if ($get_md5 -eq $true -and (Get-Member -inputobject $params -name "get_md5") ) {
@ -108,7 +92,7 @@ If (Test-Path -Path $path)
# Initial values
$result.stat.isdir = $false
$result.stat.islink = $false
$result.stat.islnk = $false
$result.stat.isshared = $false
# Need to use -Force so it picks up hidden files
@ -124,7 +108,7 @@ If (Test-Path -Path $path)
$attributes = @()
foreach ($attribute in ($info.Attributes -split ',')) {
$attributes += $attribute.Trim();
$attributes += $attribute.Trim()
}
$result.stat.attributes = $info.Attributes.ToString()
$result.stat.isarchive = $attributes -contains "Archive"
@ -133,11 +117,11 @@ If (Test-Path -Path $path)
If ($info)
{
$accesscontrol = $info.GetAccessControl();
$accesscontrol = $info.GetAccessControl()
}
Else
{
$accesscontrol = $null;
$accesscontrol = $null
}
$result.stat.owner = $accesscontrol.Owner
@ -145,7 +129,7 @@ If (Test-Path -Path $path)
If ($attributes -contains 'ReparsePoint')
{
# TODO: Find a way to differenciate between soft and junction links
$result.stat.islink = $true
$result.stat.islnk = $true
$result.stat.isdir = $true
# Try and get the symlink source, can result in failure if link is broken
try {
@ -165,7 +149,7 @@ If (Test-Path -Path $path)
$result.stat.sharename = $share_info.Name
}
$dir_files_sum = Get-ChildItem $info.FullName -Recurse | Measure-Object -property length -sum;
$dir_files_sum = Get-ChildItem $info.FullName -Recurse | Measure-Object -property length -sum
If ($dir_files_sum -eq $null)
{
$result.stat.size = 0
@ -180,11 +164,11 @@ If (Test-Path -Path $path)
$result.stat.extension = $info.Extension
If ($get_md5) {
$result.stat.md5 = Get-Hash -Path $path -Algorithm "md5"
$result.stat.md5 = Get-FileChecksum -path $path -algorithm "md5"
}
If ($get_checksum) {
$result.stat.checksum = Get-Hash -Path $path -Algorithm $checksum_algorithm
$result.stat.checksum = Get-FileChecksum -path $path -algorithm $checksum_algorithm
}
}
}
@ -193,4 +177,4 @@ Else
$result.stat.exists = $false
}
Exit-Json $result;
Exit-Json $result

View file

@ -150,7 +150,7 @@ stat:
returned: success, path exists
type: boolean
sample: True
islink:
islnk:
description: if the path is a symbolic link or junction or not
returned: success, path exists
type: boolean