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:
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.
The initial
if
check of the DeleteDotChocolatey function is replaced with aswitch
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: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.