bcurran3 / ChocolateyPackages

My published Chocolatey packages
206 stars 94 forks source link

[URGENT] choco-cleaner nukes all .chocolatey files (except for packages.config) when using pre-release chocolatey #329

Closed God-damnit-all closed 1 year ago

God-damnit-all commented 1 year ago

Using Choco-Cleaner.ps1 v1.1.0 (2023-06-12)

This is first triggered by choco-cleaner not being able to parse the version of choco.exe:

Cannot convert value "2.1.0-alpha-20230614" to type "System.Version". Error: "Input string was not in a correct
format."
At c:\tools\bcurran3\choco-cleaner.ps1:423 char:5
+ if (([System.Version]([System.Diagnostics.FileVersionInfo]::GetVersio ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocation

You cannot call a method on a null-valued expression.
At c:\tools\bcurran3\choco-cleaner.ps1:428 char:5
+     $InstalledPackages=$InstalledPackages.replace("|",".")
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

This causes line 423's else block to trigger, which is $InstalledPackages = & choco list -lo -r -y and this just causes choco to print out the help section since it no longer recognizes -lo since 2.0. This makes it end up removing everything in .chocolatey except for packages.config

ekoam commented 1 year ago

Same issue here. I found out that Powershell cannot cast strings like "2.1.0-alpha-20230614" to [System.Version], so the if condition fails and the variable $InstalledPackages is not set to any value (for instance, try to type [System.Version]"2.1.0-alpha-20230614" and [System.Version]"2.1.0" in Powershell). However, typecasting is probably unnecessary here because one can simply use [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:chocolateyinstall\choco.exe").ProductMajorPart to retrieve the major version number. This should solve the problem.

bcurran3 commented 1 year ago

@ekoam - Thanks. I've tested and will push an update with that change.

bcurran3 commented 1 year ago

Updated.

choco install choco-cleaner --version=1.1.1

God-damnit-all commented 1 year ago

@ekoam - Thanks. I've tested and will push an update with that change.

You kinda ignored my PR. #330

The ProductMajorPart property is definitely a great find, but there are aspects to my PR that would also be a good improvement. But since I didn't get a reply to it, I'm not even sure if it's worth the time incorporating.

bcurran3 commented 1 year ago

Sorry, didn't see it until now.