chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.29k stars 902 forks source link

Replace legacy Chocolatey Community Repository on upgrade #2593

Open corbob opened 2 years ago

corbob commented 2 years ago

Description

Currently when upgrading Chocolatey, the configuration file is left largely alone. Since the community repository has been moved to https://community.chocolatey.org/api/v2/, it would be beneficial to change this source on upgrade if it's in there as one of the old (or possibly manually updated and slightly incorrect) incarnations http[s]://chocolatey.org/api/v2[/] or http[s]://community.chocolatey.org/api/v2[^/].

Thinking about this, a naive check could simply be something like:

if ($source -match 'chocolatey.org/api/v2' -and $source -notmatch 'https://community.chocolatey.org/api/v2/')
{
  # Handle correcting the source
}

Reason for this change

If we ever opt to change the redirect behaviour in the future, this will ensure nothing breaks.

TheCakeIsNaOH commented 2 years ago

IMHO, it might be better to reset/update the chocolatey source when it is read in as an object, that way, there is no need for regex that might match on an incorrect line (like someone setting another config setting to something including chocolatey.org).

This either could be done inside choco, like the licensed source is setup: https://github.com/chocolatey/choco/blob/develop/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs#L77

Or the powershell install script could read in the config file as an xml object, and edit it there.