From bb229c8fa2e9557a8a7ec108fa54bc111102fb33 Mon Sep 17 00:00:00 2001 From: Dreamcat4 Date: Wed, 20 Apr 2016 20:26:27 +0100 Subject: [PATCH 1/2] fix: win_stat - fixes for strict-mode --- windows/win_stat.ps1 | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/windows/win_stat.ps1 b/windows/win_stat.ps1 index 06484f3d1cc..366652249b6 100644 --- a/windows/win_stat.ps1 +++ b/windows/win_stat.ps1 @@ -21,7 +21,10 @@ $params = Parse-Args $args $true; function Date_To_Timestamp($start_date, $end_date) { - Write-Output (New-TimeSpan -Start $start_date -End $end_date).TotalSeconds + If($start_date -and $end_date) + { + Write-Output (New-TimeSpan -Start $start_date -End $end_date).TotalSeconds + } } $path = Get-Attr $params "path" $FALSE; @@ -42,23 +45,44 @@ $result = New-Object psobject @{ If (Test-Path $path) { Set-Attr $result.stat "exists" $TRUE; + $info = Get-Item $path; + $iscontainer = Get-Attr $info "PSIsContainer" $null; + $length = Get-Attr $info "Length" $null; + $extension = Get-Attr $info "Extension" $null; + $attributes = Get-Attr $info "Attributes" ""; + If ($info) + { + $accesscontrol = $info.GetAccessControl(); + } + Else + { + $accesscontrol = $null; + } + $owner = Get-Attr $accesscontrol "Owner" $null; + $creationtime = Get-Attr $info "CreationTime" $null; + $lastaccesstime = Get-Attr $info "LastAccessTime" $null; + $lastwritetime = Get-Attr $info "LastWriteTime" $null; + + $epoch_date = Get-Date -Date "01/01/1970" - If ($info.PSIsContainer) + If ($iscontainer) { Set-Attr $result.stat "isdir" $TRUE; } Else { Set-Attr $result.stat "isdir" $FALSE; - Set-Attr $result.stat "size" $info.Length; + Set-Attr $result.stat "size" $length; } - Set-Attr $result.stat "extension" $info.Extension; - Set-Attr $result.stat "attributes" $info.Attributes.ToString(); - Set-Attr $result.stat "owner" $info.GetAccessControl().Owner; - Set-Attr $result.stat "creationtime" (Date_To_Timestamp $epoch_date $info.CreationTime); - Set-Attr $result.stat "lastaccesstime" (Date_To_Timestamp $epoch_date $info.LastAccessTime); - Set-Attr $result.stat "lastwritetime" (Date_To_Timestamp $epoch_date $info.LastWriteTime); + Set-Attr $result.stat "extension" $extension; + Set-Attr $result.stat "attributes" $attributes.ToString(); + # Set-Attr $result.stat "owner" $getaccesscontrol.Owner; + # Set-Attr $result.stat "owner" $info.GetAccessControl().Owner; + Set-Attr $result.stat "owner" $owner; + Set-Attr $result.stat "creationtime" (Date_To_Timestamp $epoch_date $creationtime); + Set-Attr $result.stat "lastaccesstime" (Date_To_Timestamp $epoch_date $lastaccesstime); + Set-Attr $result.stat "lastwritetime" (Date_To_Timestamp $epoch_date $lastwritetime); } Else { From b3584c5ffebf8c697dab540b88d1515f6897c221 Mon Sep 17 00:00:00 2001 From: Dreamcat4 Date: Wed, 20 Apr 2016 20:26:44 +0100 Subject: [PATCH 2/2] fix: win_get_url - fixes for strict-mode --- windows/win_get_url.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/win_get_url.ps1 b/windows/win_get_url.ps1 index 75bef615ab7..1f0e6580ddc 100644 --- a/windows/win_get_url.ps1 +++ b/windows/win_get_url.ps1 @@ -105,7 +105,7 @@ Else { Fail-Json $result "Error when requesting Last-Modified date from $url $($_.Exception.Message)" } - If ((Get-Date -Date $webLastMod ) -lt $fileLastMod) { + If (($webLastMod) -and ((Get-Date -Date $webLastMod ) -lt $fileLastMod)) { $result.changed = $false } Else { Download-File -result $result -url $url -dest $dest -username $username -password $password -proxy_url $proxy_url -proxy_username $proxy_username -proxy_password $proxy_password