okibcn / wslcompact

Compacts the size of the ever-growing WSL vhdx images.
https://github.com/okibcn/wslcompact
GNU General Public License v3.0
800 stars 19 forks source link

Issue calculating temp space #37

Open rawiriblundell opened 5 days ago

rawiriblundell commented 5 days ago

On first run of wslcompact, I encountered:

 WARNING: there isn't enough free space in temp drive C to process Ubuntu-20.04.
          There are only 10259 MB available.

 Please, change the TEMP folder to a drive with at least 0 MB of free space.
 You cand do it by typing $env:TEMP="Z:/your/new/temp/folder" before using wslcompact.

So I followed the instructions:

$env:TEMP="d:\wsltmp"

Then I started getting:

 Current size:   36260 MB
 Estimated size: 15537 +/- 379 MB
 The estimated process time using an SSD is about 4 minutes.
Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.
At C:\Users\Rawiri.Blundell\[redacted]\WindowsPowerShell\Modules\WslCompact\WslCompact.psm1:85 char:17
+             if (($estimated * $sf) -lt ($freedisk / 1MB)) {
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Following the code, we have this line:

$freedisk = (Get-PSDrive $env:TEMP[0]).free

If I follow that manually, I get two results:

Get-PSDrive $env:TEMP[0]

Name           Used (GB)     Free (GB) Provider      Root                                                            CurrentLocation
----           ---------     --------- --------      ----                                                            ---------------
D                  16.44         41.28 FileSystem    D:\
d                  16.44         41.28 FileSystem    d:\

(Get-PSDrive $env:TEMP[0]).free
44320555008
44320555008

I don't know if this is normal behaviour for PowerShell.

Setting the $freedisk assignment to this:

$freedisk = (Get-PSDrive $env:TEMP[0] | Select-Object -First 1).free

Allows the process to continue, but I'm not sure if that's necessarily the best solution.