Skip to content

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
* release/3.3.0:
  (maint) Add missing . at end of template
  (#40) Handle long file paths when caching files
  (maint) End Chocolatey Specific Modification
  (#38) Allow getting the system proxy
  (build) Starting building 3.3.0 on develop branch
  • Loading branch information
gep13 committed Jun 13, 2023
2 parents e6e85ac + 99b2a3f commit 420351e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .templates/default/issue-note.sbn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- {{ issue.title }} - see [#{{ issue.number }}]({{ issue.html_url }})
- {{ issue.title }} - see [#{{ issue.number }}]({{ issue.html_url }}).
2 changes: 1 addition & 1 deletion build/config.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- ** Change for each new version -->
<!-- when changing any of the NuGetVersion props below, run tools-local\ship-public-apis -->
<MajorNuGetVersion Condition="'$(MajorNuGetVersion)' == ''">3</MajorNuGetVersion>
<MinorNuGetVersion Condition="'$(MinorNuGetVersion)' == ''">2</MinorNuGetVersion>
<MinorNuGetVersion Condition="'$(MinorNuGetVersion)' == ''">3</MinorNuGetVersion>
<PatchNuGetVersion Condition="'$(PatchNuGetVersion)' == ''">0</PatchNuGetVersion>
<SemanticVersion Condition=" '$(SemanticVersion)' == '' ">$(MajorNuGetVersion).$(MinorNuGetVersion).$(PatchNuGetVersion)</SemanticVersion>

Expand Down
19 changes: 17 additions & 2 deletions src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,26 @@ 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;
}

//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

// Check if the user has configured proxy details in settings or in the environment.
Expand Down
83 changes: 55 additions & 28 deletions src/NuGet.Core/NuGet.Protocol/HttpSource/HttpSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ public virtual async Task<T> GetAsync<T>(
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 =>
Expand Down Expand Up @@ -163,30 +185,11 @@ public virtual async Task<T> GetAsync<T>(

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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
//////////////////////////////////////////////////////////

}
}

0 comments on commit 420351e

Please sign in to comment.