From 9a36b4019e0c7afb371318b8d7b8a954ea6428f8 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Sat, 15 Jul 2023 11:29:34 -0500 Subject: [PATCH] (#1485) Display package source during install/upgrade This logs the package source uri to info before downloading nupkgs during both install and upgrade. Additionally, it debug logs the download URI that the nupkg available at. The information outputs for both individual package installs/upgrades, and for dependencies that get installed/upgraded by their parent package. This information is especially useful when multiple sources are in play, so the user can determine where individual packages are coming from. --- .../scenarios/InstallScenarios.cs | 20 +++++++++++++++++++ .../scenarios/UpgradeScenarios.cs | 20 +++++++++++++++++++ .../services/NugetService.cs | 6 ++++++ 3 files changed, 46 insertions(+) diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index 53f21c6f44..df6d8463f9 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -323,6 +323,26 @@ public void Should_have_a_version_of_one_dot_zero_dot_zero() _packageResult.Version.Should().Be(TestVersion()); } + [Fact] + public void Should_contain_message_with_source() + { + var message = "Downloading package from source '{0}'".FormatWith(Configuration.Sources); + + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToString()).WhoseValue.Should() + .Contain(message); + } + + [Fact] + public void Should_contain_message_with_download_uri() + { + var packagePath = "file:///{0}/{1}.{2}{3}".FormatWith(Configuration.Sources.Replace("\\","/"), Configuration.PackageNames, + TestVersion(), NuGetConstants.PackageExtension); + var message = "Package download location '{0}'".FormatWith(packagePath); + + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToString()).WhoseValue.Should() + .Contain(message); + } + [Fact] [WindowsOnly] [Platform(Exclude = "Mono")] diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 8b3f127f75..7e19eaa7a8 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -265,6 +265,26 @@ public void Should_match_the_upgrade_version_of_one_dot_one_dot_zero() _packageResult.Version.Should().Be("1.1.0"); } + [Fact] + public void Should_contain_message_with_source() + { + var message = "Downloading package from source '{0}'".FormatWith(Configuration.Sources); + + MockLogger.Messages.Should().ContainKey(LogLevel.Info.ToString()).WhoseValue.Should() + .Contain(message); + } + + [Fact] + public void Should_contain_message_with_download_uri() + { + var packagePath = "file:///{0}/{1}.{2}{3}".FormatWith(Configuration.Sources.Replace("\\", "/"), Configuration.PackageNames, + "1.1.0", NuGetConstants.PackageExtension); + var message = "Package download location '{0}'".FormatWith(packagePath); + + MockLogger.Messages.Should().ContainKey(LogLevel.Debug.ToString()).WhoseValue.Should() + .Contain(message); + } + [Fact] [WindowsOnly] [Platform(Exclude = "Mono")] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 354fa6ca6e..cc6fa0e067 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -803,6 +803,9 @@ Version was specified as '{0}'. It is possible that version _fileSystem.DeleteFile(pathResolver.GetInstalledPackageFilePath(packageDependencyInfo)); + this.Log().Info("Downloading package from source '{0}'".FormatWith(packageDependencyInfo.Source)); + this.Log().Debug("Package download location '{0}'".FormatWith(packageDependencyInfo.DownloadUri)); + ChocolateyProgressInfo.ShouldDisplayDownloadProgress = config.Features.ShowDownloadProgress; using (var downloadResult = downloadResource.GetDownloadResourceResultAsync( @@ -1485,6 +1488,9 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon _fileSystem.DeleteFile(pathResolver.GetInstalledPackageFilePath(packageDependencyInfo)); + this.Log().Info("Downloading package from source '{0}'".FormatWith(packageDependencyInfo.Source)); + this.Log().Debug("Package download location '{0}'".FormatWith(packageDependencyInfo.DownloadUri)); + ChocolateyProgressInfo.ShouldDisplayDownloadProgress = config.Features.ShowDownloadProgress; using (var downloadResult = downloadResource.GetDownloadResourceResultAsync(