dotnet / install-scripts

MIT License
127 stars 70 forks source link

C# plugin fails to load because 'dotnet-install.ps1' fails with diskspace error #374

Closed brennennen closed 11 months ago

brennennen commented 12 months ago

The issue text generated by visual studio is an empty file. Digging into the issue, it looks like dotnet-install.ps1 is trying to determine how much disk space is available and throws an error if no disk space is available even though I have ~300GB free.

Issue:

Get-PSDrive is called in script dotnet-install.ps1 function Prepare-Install-Directory. Get-PSDrive appears to return null for Free and 0 for Used in certain scenarios even when there is plenty of space on the drive.

PS C:\Users\MyUser> Get-PSDrive -N C | select Free,Used
Free Used
 ---- ----
        0 

Requested fix:

In dotnet-install.ps1 function Prepare-Install-Directory, before the check to throw the error. Could yall check to see if Free and Used are null or zero and just display a warning instead? If the disk has 0 used data and null free data, that should be a signal that the Get-PSDrive call is not functioning correctly and can't be trusted.

Work around:

Comment out the line that throws the exception and mark the file as read only.

Snippets

The issue is in the function below: dotnet-install.ps1:1102

function Prepare-Install-Directory {
    New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null

    $installDrive = $((Get-Item $InstallRoot -Force).PSDrive.Name);
    $diskInfo = $null
    try{
        $diskInfo = Get-PSDrive -Name $installDrive
    }
    catch{
        Say-Warning "Failed to check the disk space. Installation will continue, but it may fail if you do not have enough disk space."
    }
    # HERE: Requested fix here, add a check to see if Used and Free are both null/zero. If they are skip the below if block that can throw an error and just display a warning.
    # HERE: if (diskInfo.Free == 0 && diskInfo.Used == 0) {Say-Warning "..." and return}

    # HERE: Error preventing usage being thrown here.
    if ( ($null -ne $diskInfo) -and ($diskInfo.Free / 1MB -le 100)) {
        throw "There is not enough disk space on drive ${installDrive}:" # HERE: Comment this line out as a work around.
    }
}

Full Get-PSDrive output:

PS C:\Users\MyUser> Get-PSDrive -N C | select *

Used            : 0
Free            :
CurrentLocation : Users\MyUser
Name            : C
Provider        : Microsoft.PowerShell.Core\FileSystem
Root            : C:\
Description     : Windows
MaximumSize     :
Credential      : System.Management.Automation.PSCredential
DisplayRoot     :

My C drive, which vscode is installed on, has plenty of free space (around 300GB).

PS C:\Users\MyUser> [System.IO.DriveInfo]::GetDrives() | Format-Table

Name DriveType DriveFormat IsReady AvailableFreeSpace TotalFreeSpace     TotalSize RootDirectory VolumeLabel
---- --------- ----------- ------- ------------------ --------------     --------- ------------- -----------
C:\      Fixed NTFS           True       355307118592   355307118592 1023235059712 C:\           Windows

OS Version

PS C:\Users\MyUser> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19044  0                                                                                                                                                                                                                             
baronfel commented 11 months ago

Great analysis - going to forward to the install-scripts repo for the fix.

YuliiaKovalova commented 11 months ago

The issue is addressed. The change will be deployed later this week.