From 2469eeb63a9f89d8c71b5f787c89f05ee6726d1a Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 5 Jun 2023 15:25:59 +0100 Subject: [PATCH 1/5] (build) Starting building 3.3.0 on develop branch Now that we have shipped 3.2.0 of the Chocolatey.NuGet.Client assemblies, we should started building 3.3.0 on the develop branch. --- build/config.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/config.props b/build/config.props index 79e451b577b..71f7e3c967f 100644 --- a/build/config.props +++ b/build/config.props @@ -13,7 +13,7 @@ 3 - 2 + 3 0 $(MajorNuGetVersion).$(MinorNuGetVersion).$(PatchNuGetVersion) From e8d750ee07f11580f5ceb2c7e1c507bbc3be24e8 Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Mon, 5 Jun 2023 14:17:53 -0700 Subject: [PATCH 2/5] (#38) Allow getting the system proxy When Chocolatey configures the Proxy settings, it passes in a WebProxy option with the appropriate settings. If it doesn't have a proxy setting, then we should defer to the System proxy settings instead of a bare WebProxy. --- .../NuGet.Configuration/Proxy/ProxyCache.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs b/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs index 2946d9598b1..29fb839cb04 100644 --- a/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs +++ b/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs @@ -64,7 +64,22 @@ public IWebProxy GetProxy(Uri sourceUri) if (_isProxyOverridden) { - return _overrideProxy; + if (_overrideProxy != null) + { + return _overrideProxy; + } + + // This is explicitly a copy of the below code so that Chocolatey can get the System proxy settings without the NuGet User configured settings. +#if !IS_CORECLR + if (IsSystemProxySet(sourceUri)) + { + var systemProxy = GetSystemProxy(sourceUri); + TryAddProxyCredentialsToCache(systemProxy); + systemProxy.Credentials = this; + return systemProxy; + } +#endif + return null; } ////////////////////////////////////////////////////////// From f30d5b700f3796f50c58fee93e1ddf1f3d89c2ac Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Mon, 5 Jun 2023 14:10:54 -0700 Subject: [PATCH 3/5] (maint) End Chocolatey Specific Modification --- src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs b/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs index 29fb839cb04..eced2894b3c 100644 --- a/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs +++ b/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs @@ -83,7 +83,7 @@ public IWebProxy GetProxy(Uri sourceUri) } ////////////////////////////////////////////////////////// - // Start - Chocolatey Specific Modification + // End - Chocolatey Specific Modification ////////////////////////////////////////////////////////// // Check if the user has configured proxy details in settings or in the environment. From da65b928251276eb8b43582d10d7d61379109b6b Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Tue, 13 Jun 2023 10:46:05 +0100 Subject: [PATCH 4/5] (#40) Handle long file paths when caching files During testing, it was found that there are cases where a very long query string was causing a problem when caching the file earlier in the callstack than the earlier testing. This problem is caused when a call into a BCL method throws a long file path exception, even though the Operating System has been enabled to use long path file support. Due to this, we have introduced a check to see if the file path is longer than the allowed length, and if it is, immediately create the hashed filename. This commit adds a new helper method, GetHashedCacheFileName. which is used to calculate the hashed file name, in a single location, rather than duplicating the work in multiple places. --- .../NuGet.Protocol/HttpSource/HttpSource.cs | 83 ++++++++++++------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpSource.cs b/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpSource.cs index 62c9b684f3e..4d77141db02 100644 --- a/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpSource.cs +++ b/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpSource.cs @@ -83,6 +83,28 @@ public virtual async Task GetAsync( request.CacheKey, request.CacheContext); + ////////////////////////////////////////////////////////// + // Start - Chocolatey Specific Modification + ////////////////////////////////////////////////////////// + + // There are times when the URI that is being queried results in a CacheFile name that + // is greater that the allowed 259 characters for a file path. While .NET "should" handle + // this, some methods in the BCL don't, and as a result, we need to create a hashed + // version of the file path, so that we can cache the file with that name, and therefore + // an exception will not be thrown. + // NOTE: We are aware that the long path limit is documented as 260, however, during some + // tests, it wasn't immediately clear that this was respected, so we are going one character + // less, just to be on the safe side. + if (cacheResult.NewFile.Length > 259 || cacheResult.CacheFile.Length > 259) + { + cacheResult.NewFile = GetHashedCacheFileName(cacheResult.NewFile); + cacheResult.CacheFile = GetHashedCacheFileName(cacheResult.CacheFile); + } + + ////////////////////////////////////////////////////////// + // End - Chocolatey Specific Modification + ////////////////////////////////////////////////////////// + return await ConcurrencyUtilities.ExecuteWithFileLockedAsync( cacheResult.CacheFile, action: async lockedToken => @@ -163,30 +185,11 @@ public virtual async Task GetAsync( if (!request.CacheContext.DirectDownload) { - try - { - await HttpCacheUtility.CreateCacheFileAsync( - cacheResult, - throttledResponse.Response, - request.EnsureValidContents, - lockedToken); - } - catch (Exception) - { - // If an exception is thrown, assume that this is due to long path name, - // and attempt to save if again in a hashed Uri file name - var newFileInfo = new FileInfo(cacheResult.NewFile); - var cacheFileInfo = new FileInfo(cacheResult.CacheFile); - - cacheResult.NewFile = Path.Combine(newFileInfo.Directory.FullName, CachingUtility.ComputeHash(newFileInfo.Name)); - cacheResult.CacheFile = Path.Combine(cacheFileInfo.Directory.FullName, CachingUtility.ComputeHash(cacheFileInfo.Name)); - - await HttpCacheUtility.CreateCacheFileAsync( - cacheResult, - throttledResponse.Response, - request.EnsureValidContents, - lockedToken); - } + await HttpCacheUtility.CreateCacheFileAsync( + cacheResult, + throttledResponse.Response, + request.EnsureValidContents, + lockedToken); using (var httpSourceResult = new HttpSourceResult( HttpSourceResultStatus.OpenedFromDisk, @@ -478,19 +481,25 @@ public string HttpCacheDirectory protected virtual Stream TryReadCacheFile(string uri, TimeSpan maxAge, string cacheFile) { + ////////////////////////////////////////////////////////// + // Start - Chocolatey Specific Modification + ////////////////////////////////////////////////////////// + // Do not need the uri here var cachedFile = CachingUtility.ReadCacheFile(maxAge, cacheFile); - // We need to check incase the cached file name was tool long, and the + // We need to check incase the cached file name was too long, and the // file was saved in a truncated form if (cachedFile == null) { - var cacheFileInfo = new FileInfo(cacheFile); - var hashedUri = CachingUtility.ComputeHash(cacheFileInfo.Name); - cachedFile = CachingUtility.ReadCacheFile(maxAge, Path.Combine(cacheFileInfo.Directory.FullName, hashedUri)); + cachedFile = CachingUtility.ReadCacheFile(maxAge, GetHashedCacheFileName(cacheFile)); } return cachedFile; + + ////////////////////////////////////////////////////////// + // End - Chocolatey Specific Modification + ////////////////////////////////////////////////////////// } public static HttpSource Create(SourceRepository source) @@ -575,5 +584,23 @@ public void Dispose() } } } + + ////////////////////////////////////////////////////////// + // Start - Chocolatey Specific Modification + ////////////////////////////////////////////////////////// + + private string GetHashedCacheFileName(string cacheFile) + { + var cacheFileExtension = Path.GetExtension(cacheFile); + var cacheFileName = Path.GetFileNameWithoutExtension(cacheFile); + var cacheFileDirectoryName = cacheFile.Substring(0, cacheFile.LastIndexOf(Path.DirectorySeparatorChar)); + + return Path.Combine(cacheFileDirectoryName, CachingUtility.ComputeHash(cacheFileName) + cacheFileExtension); + } + + ////////////////////////////////////////////////////////// + // End - Chocolatey Specific Modification + ////////////////////////////////////////////////////////// + } } From 99b2a3f359abb29a2975217d4c36ed00d62a1937 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Tue, 13 Jun 2023 14:50:28 +0100 Subject: [PATCH 5/5] (maint) Add missing . at end of template This is required in order to follow the release notes format that has been agreed within the team. --- .templates/default/issue-note.sbn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.templates/default/issue-note.sbn b/.templates/default/issue-note.sbn index 0bcf3a89030..edfc1fdd322 100644 --- a/.templates/default/issue-note.sbn +++ b/.templates/default/issue-note.sbn @@ -1 +1 @@ -- {{ issue.title }} - see [#{{ issue.number }}]({{ issue.html_url }}) +- {{ issue.title }} - see [#{{ issue.number }}]({{ issue.html_url }}).