fix: win_stat - fixes for strict-mode

pull/18777/head
Dreamcat4 9 years ago committed by Matt Clay
parent 4141cc5548
commit c85a82ad00

@ -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
{

Loading…
Cancel
Save