Change free/used calculation to be consistent across platforms
add a couple of tests to validate return values
This commit is contained in:
parent
9597a47689
commit
1bbdaa7ea8
|
@ -52,29 +52,15 @@ namespace System.Management.Automation.Runspaces
|
||||||
if($this.Provider.ImplementingType -eq
|
if($this.Provider.ImplementingType -eq
|
||||||
[Microsoft.PowerShell.Commands.FileSystemProvider])
|
[Microsoft.PowerShell.Commands.FileSystemProvider])
|
||||||
{
|
{
|
||||||
if ( ! $IsWindows ) {
|
$driveInfo = [System.IO.DriveInfo]::New($this.Root)
|
||||||
$driveInfo = ([System.IO.DriveInfo]::GetDrives()|where-object {$_.Name -eq $this.Root}|Select-Object -first 1)
|
if ( $driveInfo.IsReady ) { $driveInfo.TotalSize - $driveInfo.AvailableFreeSpace }
|
||||||
$driveInfo.TotalSize - $driveInfo.AvailableFreeSpace
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$driveRoot = ([System.IO.DirectoryInfo] $this.Root).Name.Replace('\','')
|
|
||||||
$drive = Get-CimInstance Win32_LogicalDisk -Filter ""DeviceId='$driveRoot'""
|
|
||||||
$drive.Size - $drive.FreeSpace
|
|
||||||
}
|
|
||||||
}"), null));
|
}"), null));
|
||||||
td4.Members.Add("Free",
|
td4.Members.Add("Free",
|
||||||
new ScriptPropertyData(@"Free", GetScriptBlock(@"## Ensure that this is a FileSystem drive
|
new ScriptPropertyData(@"Free", GetScriptBlock(@"## Ensure that this is a FileSystem drive
|
||||||
if($this.Provider.ImplementingType -eq
|
if($this.Provider.ImplementingType -eq
|
||||||
[Microsoft.PowerShell.Commands.FileSystemProvider])
|
[Microsoft.PowerShell.Commands.FileSystemProvider])
|
||||||
{
|
{
|
||||||
if ( ! $IsWindows ) {
|
[System.IO.DriveInfo]::New($this.Root).AvailableFreeSpace
|
||||||
([System.IO.DriveInfo]::GetDrives()|where-object {$_.Name -eq $this.Root}|Select-Object -first 1).AvailableFreeSpace
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$driveRoot = ([System.IO.DirectoryInfo] $this.Root).Root.Name.Replace('\','')
|
|
||||||
$drive = Get-CimInstance Win32_LogicalDisk -Filter ""DeviceId='$driveRoot'""
|
|
||||||
$drive.FreeSpace
|
|
||||||
}
|
|
||||||
}"), null));
|
}"), null));
|
||||||
yield return td4;
|
yield return td4;
|
||||||
|
|
||||||
|
|
|
@ -44,4 +44,12 @@ Describe "Get-PSDrive" -Tags "CI" {
|
||||||
!(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should Be $True
|
!(Get-PSDrive fake -ErrorAction SilentlyContinue) | Should Be $True
|
||||||
Get-PSDrive fake -ErrorAction SilentlyContinue | Should BeNullOrEmpty
|
Get-PSDrive fake -ErrorAction SilentlyContinue | Should BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
It "Should be able to determine the amount of free space of a drive" {
|
||||||
|
$dInfo = Get-PSDrive TESTDRIVE
|
||||||
|
$dInfo.Free -ge 0 | Should be $true
|
||||||
|
}
|
||||||
|
It "Should be able to determine the amount of Used space of a drive" {
|
||||||
|
$dInfo = Get-PSDrive TESTDRIVE
|
||||||
|
$dInfo.Used -ge 0 | Should be $true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue