From 12f52a27c4d9ab82e71d8a888e17640062edcc80 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Fri, 20 Feb 2026 12:00:01 -0800 Subject: [PATCH 1/5] Replace SharpCompress with System.Formats.Tar in tests --- .../Microsoft.DotNet.Docker.Tests.csproj | 1 - .../PowerShellTests.cs | 2 -- .../SdkImageTests.cs | 22 +++++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj b/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj index e72fcffb52..cbe6c0229b 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj +++ b/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj @@ -15,7 +15,6 @@ - diff --git a/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs b/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs index 9564c9a3ba..d125daa3f6 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs @@ -15,8 +15,6 @@ using System.Threading.Tasks; using Polly; using Polly.Retry; -using SharpCompress.Common; -using SharpCompress.Readers; using Xunit; using Xunit.Abstractions; diff --git a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs index 9fb098b44f..e12c4a9579 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs @@ -14,8 +14,8 @@ using System.Threading.Tasks; using Polly; using Polly.Retry; -using SharpCompress.Common; -using SharpCompress.Readers; +using System.Formats.Tar; +using System.IO.Compression; using Xunit; using Xunit.Abstractions; @@ -283,9 +283,23 @@ private IEnumerable GetActualSdkContents(ProductImageData im private static IEnumerable EnumerateArchiveContents(string path) { using FileStream fileStream = File.OpenRead(path); - using IReader reader = ReaderFactory.Open(fileStream); + using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); + using var tarReader = new TarReader(gzipStream); using TempFolderContext tempFolderContext = FileHelper.UseTempFolder(); - reader.WriteAllToDirectory(tempFolderContext.Path, new ExtractionOptions() { ExtractFullPath = true }); + + while (tarReader.GetNextEntry() is TarEntry entry) + { + string destinationPath = Path.Combine(tempFolderContext.Path, entry.Name); + if (entry.EntryType is TarEntryType.Directory) + { + Directory.CreateDirectory(destinationPath); + } + else if (entry.EntryType is TarEntryType.RegularFile) + { + Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!); + entry.ExtractToFile(destinationPath, overwrite: false); + } + } foreach (FileInfo file in new DirectoryInfo(tempFolderContext.Path).EnumerateFiles("*", SearchOption.AllDirectories)) { From 23ea44dd8534ed6f6d800b779257b0cd2ce1977b Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Fri, 20 Feb 2026 14:03:35 -0800 Subject: [PATCH 2/5] Support both zip and tar.gz --- .../SdkImageTests.cs | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs index e12c4a9579..3405f2d30a 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs @@ -280,34 +280,15 @@ private IEnumerable GetActualSdkContents(ProductImageData im .OrderBy(fileInfo => fileInfo.Path); } - private static IEnumerable EnumerateArchiveContents(string path) + private static IEnumerable EnumerateArchiveContents(string extractedPath) { - using FileStream fileStream = File.OpenRead(path); - using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); - using var tarReader = new TarReader(gzipStream); - using TempFolderContext tempFolderContext = FileHelper.UseTempFolder(); - - while (tarReader.GetNextEntry() is TarEntry entry) - { - string destinationPath = Path.Combine(tempFolderContext.Path, entry.Name); - if (entry.EntryType is TarEntryType.Directory) - { - Directory.CreateDirectory(destinationPath); - } - else if (entry.EntryType is TarEntryType.RegularFile) - { - Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!); - entry.ExtractToFile(destinationPath, overwrite: false); - } - } - - foreach (FileInfo file in new DirectoryInfo(tempFolderContext.Path).EnumerateFiles("*", SearchOption.AllDirectories)) + foreach (FileInfo file in new DirectoryInfo(extractedPath).EnumerateFiles("*", SearchOption.AllDirectories)) { using SHA512 sha512 = SHA512.Create(); byte[] sha512HashBytes = sha512.ComputeHash(File.ReadAllBytes(file.FullName)); string sha512Hash = BitConverter.ToString(sha512HashBytes).Replace("-", string.Empty); yield return new SdkContentFileInfo( - file.FullName.Substring(tempFolderContext.Path.Length), sha512Hash); + file.FullName.Substring(extractedPath.Length), sha512Hash); } } @@ -326,7 +307,20 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken => await s_httpClient.DownloadFileAsync(new Uri(sdkUrl), sdkFile); }); - files = EnumerateArchiveContents(sdkFile) + using TempFolderContext extractFolder = FileHelper.UseTempFolder(); + + if (sdkUrl.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) + { + ZipFile.ExtractToDirectory(sdkFile, extractFolder.Path); + } + else + { + using FileStream fileStream = File.OpenRead(sdkFile); + using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); + TarFile.ExtractToDirectory(gzipStream, extractFolder.Path, overwriteFiles: false); + } + + files = EnumerateArchiveContents(extractFolder.Path) .OrderBy(file => file.Path) .ToArray(); From ed69aaa8fcbcb20492f4505c016a60bd8c00b036 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Fri, 20 Feb 2026 14:04:06 -0800 Subject: [PATCH 3/5] Reorder methods --- .../SdkImageTests.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs index 3405f2d30a..be88f44793 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs @@ -280,18 +280,6 @@ private IEnumerable GetActualSdkContents(ProductImageData im .OrderBy(fileInfo => fileInfo.Path); } - private static IEnumerable EnumerateArchiveContents(string extractedPath) - { - foreach (FileInfo file in new DirectoryInfo(extractedPath).EnumerateFiles("*", SearchOption.AllDirectories)) - { - using SHA512 sha512 = SHA512.Create(); - byte[] sha512HashBytes = sha512.ComputeHash(File.ReadAllBytes(file.FullName)); - string sha512Hash = BitConverter.ToString(sha512HashBytes).Replace("-", string.Empty); - yield return new SdkContentFileInfo( - file.FullName.Substring(extractedPath.Length), sha512Hash); - } - } - private async Task> GetExpectedSdkContentsAsync(ProductImageData imageData) { string sdkUrl = GetSdkUrl(imageData); @@ -330,6 +318,19 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken => return files; } + private static IEnumerable EnumerateArchiveContents(string extractedPath) + { + foreach (FileInfo file in new DirectoryInfo(extractedPath).EnumerateFiles("*", SearchOption.AllDirectories)) + { + using SHA512 sha512 = SHA512.Create(); + byte[] sha512HashBytes = sha512.ComputeHash(File.ReadAllBytes(file.FullName)); + string sha512Hash = BitConverter.ToString(sha512HashBytes).Replace("-", string.Empty); + yield return new SdkContentFileInfo( + file.FullName.Substring(extractedPath.Length), sha512Hash); + } + } + + private static string GetSdkVersionFileLabel(string sdkBuildVersion, string dotnetVersion) { // This should be kept in sync with the template for computing the SDK version file: From 90eee50be700900a8620505cf476a4b071f8c143 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Fri, 20 Feb 2026 14:09:21 -0800 Subject: [PATCH 4/5] Simplify EnumerateArchiveContents --- .../SdkImageTests.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs index be88f44793..c5ecd114d6 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs @@ -320,13 +320,18 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken => private static IEnumerable EnumerateArchiveContents(string extractedPath) { - foreach (FileInfo file in new DirectoryInfo(extractedPath).EnumerateFiles("*", SearchOption.AllDirectories)) + IEnumerable files = Directory.EnumerateFiles(extractedPath, "*", SearchOption.AllDirectories); + + foreach (string file in files) { - using SHA512 sha512 = SHA512.Create(); - byte[] sha512HashBytes = sha512.ComputeHash(File.ReadAllBytes(file.FullName)); - string sha512Hash = BitConverter.ToString(sha512HashBytes).Replace("-", string.Empty); + string filePath = Path.GetFullPath(file); + byte[] fileData = File.ReadAllBytes(filePath); + byte[] sha512HashBytes = SHA512.HashData(fileData); + string sha512Hash = Convert.ToHexString(sha512HashBytes); + yield return new SdkContentFileInfo( - file.FullName.Substring(extractedPath.Length), sha512Hash); + path: filePath.Substring(extractedPath.Length), + sha512: sha512Hash); } } From e5a579458e875fd244bddcfe384988c2634e8342 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Fri, 20 Feb 2026 14:21:50 -0800 Subject: [PATCH 5/5] Inline EnumerateArchiveContents --- .../SdkImageTests.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs index c5ecd114d6..3cb61d9932 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs @@ -297,7 +297,7 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken => using TempFolderContext extractFolder = FileHelper.UseTempFolder(); - if (sdkUrl.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) + if (Path.GetExtension(sdkUrl).Equals(".zip", StringComparison.OrdinalIgnoreCase)) { ZipFile.ExtractToDirectory(sdkFile, extractFolder.Path); } @@ -308,7 +308,18 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken => TarFile.ExtractToDirectory(gzipStream, extractFolder.Path, overwriteFiles: false); } - files = EnumerateArchiveContents(extractFolder.Path) + files = Directory.EnumerateFiles(extractFolder.Path, "*", SearchOption.AllDirectories) + .Select(file => + { + string filePath = Path.GetFullPath(file); + string relativePath = Path.GetRelativePath(extractFolder.Path, filePath); + + byte[] fileData = File.ReadAllBytes(filePath); + byte[] sha512HashBytes = SHA512.HashData(fileData); + string sha512Hash = Convert.ToHexString(sha512HashBytes); + + return new SdkContentFileInfo(relativePath, sha512Hash); + }) .OrderBy(file => file.Path) .ToArray(); @@ -318,24 +329,6 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken => return files; } - private static IEnumerable EnumerateArchiveContents(string extractedPath) - { - IEnumerable files = Directory.EnumerateFiles(extractedPath, "*", SearchOption.AllDirectories); - - foreach (string file in files) - { - string filePath = Path.GetFullPath(file); - byte[] fileData = File.ReadAllBytes(filePath); - byte[] sha512HashBytes = SHA512.HashData(fileData); - string sha512Hash = Convert.ToHexString(sha512HashBytes); - - yield return new SdkContentFileInfo( - path: filePath.Substring(extractedPath.Length), - sha512: sha512Hash); - } - } - - private static string GetSdkVersionFileLabel(string sdkBuildVersion, string dotnetVersion) { // This should be kept in sync with the template for computing the SDK version file: