bcurran3 / ChocolateyPackages

My published Chocolatey packages
206 stars 94 forks source link

Fix choco-cleaner .chocolatey install snapshot cleanup #330

Closed God-damnit-all closed 7 months ago

God-damnit-all commented 1 year ago

The initial if check of the DeleteDotChocolatey function is replaced with a switch block that uses wIldcard matching. choco.exe's version is now evaluated in a subexpression within a string, so even if it throws an error, the switch block will still run and trigger the 'default' section.

The rest of the function will not run once $global:VersionError is flipped.

Additionally, I've noticed choco list can sometimes throw errors in stdout regarding the parsing of certain files inside .chocolatey. While it's highly unlikely these lines could lead to files that shouldn't be deleted getting targeted by the cleanup, I added something to handle filtering out them out just in case:

$InstalledPackages = $InstalledPackages.Where({ $_.Contains("|") -and $_.Contains(".") -and -not $_.Contains(" ") })

This ensures each line contains a | and a . but not any spaces, which should correspond to the expected format of each package entry. _ This happens before each | is replaced with a ._


IMPORTANT: I haven't updated the version info or chocolatey.org package files, I'll leave that to you.

I've enabled Allow edits by maintainers if you'd like to do that as part of this PR.

bcurran3 commented 7 months ago

Closing this as I am no longer creating or maintaining Chocolatey packages. Sorry, out of my control.

Hopefully you've enjoyed my work and found it useful.

Bella Ciao!