standardise the powershell FileUtils (#34969)

This commit is contained in:
Jordan Borean 2018-01-17 14:16:34 +10:00 committed by GitHub
commit 6f9f337a67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 73 deletions

View file

@ -28,11 +28,11 @@ $result = @{
cmd = $raw_command_line
}
if ($creates -and $(Test-FilePath -path $creates)) {
if ($creates -and $(Test-AnsiblePath -Path $creates)) {
Exit-Json @{msg="skipped, since $creates exists";cmd=$raw_command_line;changed=$false;skipped=$true;rc=0}
}
if ($removes -and -not $(Test-FilePath -path $removes)) {
if ($removes -and -not $(Test-AnsiblePath -Path $removes)) {
Exit-Json @{msg="skipped, since $removes does not exist";cmd=$raw_command_line;changed=$false;skipped=$true;rc=0}
}

View file

@ -56,11 +56,11 @@ $result = @{
cmd = $raw_command_line
}
if ($creates -and $(Test-FilePath -path $creates)) {
if ($creates -and $(Test-AnsiblePath -Path $creates)) {
Exit-Json @{msg="skipped, since $creates exists";cmd=$raw_command_line;changed=$false;skipped=$true;rc=0}
}
if ($removes -and -not $(Test-FilePath -path $removes)) {
if ($removes -and -not $(Test-AnsiblePath -Path $removes)) {
Exit-Json @{msg="skipped, since $removes does not exist";cmd=$raw_command_line;changed=$false;skipped=$true;rc=0}
}

View file

@ -34,7 +34,7 @@ if (Get-Member -inputobject $params -name "get_md5") {
Add-DepreactionWarning -obj $result -message "get_md5 has been deprecated along with the md5 return value, use get_checksum=True and checksum_algorithm=md5 instead" -version 2.9
}
$info = Get-FileItem -path $path
$info = Get-AnsibleItem -Path $path -ErrorAction SilentlyContinue
If ($info -ne $null) {
$epoch_date = Get-Date -Date "01/01/1970"
$attributes = @()
@ -74,7 +74,7 @@ If ($info -ne $null) {
$stat.owner = $info.GetAccessControl().Owner
# values that are set according to the type of file
if ($info.PSIsContainer) {
if ($info.Attributes.HasFlag([System.IO.FileAttributes]::Directory)) {
$stat.isdir = $true
$share_info = Get-WmiObject -Class Win32_Share -Filter "Path='$($stat.path -replace '\\', '\\')'"
if ($share_info -ne $null) {
@ -82,11 +82,14 @@ If ($info -ne $null) {
$stat.sharename = $share_info.Name
}
$dir_files_sum = Get-ChildItem $stat.path -Recurse | Measure-Object -property length -sum
if ($dir_files_sum -eq $null) {
try {
$size = 0
foreach ($file in $info.EnumerateFiles("*", [System.IO.SearchOption]::AllDirectories)) {
$size += $file.Length
}
$stat.size = $size
} catch {
$stat.size = 0
} else {
$stat.size = $dir_files_sum.Sum
}
} else {
$stat.extension = $info.Extension

View file

@ -119,7 +119,7 @@ if ($path -eq $null -and $port -eq $null -and $state -eq "drained") {
$complete = $false
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
$attempts += 1
if (Test-FilePath -path $path) {
if (Test-AnsiblePath -Path $path) {
if ($search_regex -eq $null) {
$complete = $true
break
@ -150,7 +150,7 @@ if ($path -eq $null -and $port -eq $null -and $state -eq "drained") {
$complete = $false
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
$attempts += 1
if (Test-FilePath -path $path) {
if (Test-AnsiblePath -Path $path) {
if ($search_regex -ne $null) {
$file_contents = Get-Content -Path $path -Raw
if ($file_contents -notmatch $search_regex) {