NugetService: Upgrade
and Install
methods are coupled in confusing and error-prone ways
#2914
Labels
Upgrade
and Install
methods are coupled in confusing and error-prone ways
#2914
What You Are Seeing?
This was noticed while I was looking at #2884.
The code paths involved here are in NugetService, where both
upgrade_run
andinstall_run
do some of the same work:choco/src/chocolatey/infrastructure.app/services/NugetService.cs
Lines 600 to 622 in 0466676
choco/src/chocolatey/infrastructure.app/services/NugetService.cs
Lines 378 to 436 in 0466676
There is some code here that is duplicated, and this is kind of weird and potentially problematic in that it very tightly couples
upgrade_run
toinstall_run
while also doing a lot of the same things before calling intoinstall_run
for every package being upgraded. This unintuitive coupling in part caused #2884.Interestingly, it looks as though this might result in unintended consequences, such as the code handling for passing in a
nuspec
ornupkg
file path tochoco install
only being intended to work for a single file at a time, whereasupgrade
is calling this code path for each package being upgraded, so (I haven't tested, but) it's possible thatchoco upgrade
might unintentionally accept and work with multiple paths tonupkg
ornuspec
files despitechoco install
apparently being designed to handle just one.What is Expected?
These code paths should be less entangled, and should ideally avoid double work such as having to call GetPackageManager() multiple times (when calling
choco upgrade
, this method is calledn+1
times in this code path —n
being the number of packages being upgraded).I think it should also be possible to take much of the code from the
foreach
loop ininstall_run
(linked/embedded below) and move it to a separate method that bothinstall_run
andupgrade_run
can call into, to avoidupgrade_run
needing to directly callinstall_run
and incur the double-work here.choco/src/chocolatey/infrastructure.app/services/NugetService.cs
Lines 442 to 554 in 0466676
We should also evaluate:
install_run
needs to be properly and explicitly shared toupgrade_run
?choco upgrade
and if so do we want:nuspec
/nupkg
file paths for bothchoco install
andchoco upgrade
, orchoco upgrade
in this way.Splitting out some of this duplicated logic into shared methods should also help us reduce the cognitive weight of these very large methods and make this area of the code easier to maintain in future.
How Did You Get This To Happen? (Steps to Reproduce)
N/A, found while investigating #2884
System Details
N/A
Output Log
N/A
The text was updated successfully, but these errors were encountered: