Skip to content

Commit

Permalink
Switch from 7z to zip for test archive
Browse files Browse the repository at this point in the history
This not only gets us able to address #125, but allows the test to run on .NET Core runtimes as well, since the 7z library we were using only ran on net461.
The test from #125 is still broken though, on account of not regularly running.
  • Loading branch information
AArnott committed Jun 12, 2021
1 parent b7707b3 commit ed2759e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
Expand Up @@ -25,14 +25,13 @@
<EmbeddedResource Include="ManagedGit\tree*" />
<EmbeddedResource Include="test.vcprj" />
<EmbeddedResource Include="test.prj" />
<EmbeddedResource Include="repos\submodules.7z" />
<EmbeddedResource Include="repos\*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nerdbank.GitVersioning.Tasks\Nerdbank.GitVersioning.Tasks.csproj" />
<ProjectReference Include="..\NerdBank.GitVersioning\NerdBank.GitVersioning.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="7z.NET" Version="1.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.10" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="Microsoft.Build" Version="15.1.548" ExcludeAssets="runtime" />
Expand Down
30 changes: 5 additions & 25 deletions src/NerdBank.GitVersioning.Tests/TestUtilities.cs
@@ -1,7 +1,4 @@
#if NET461
using SevenZipNET;
#endif
using Validation;
using Validation;

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -67,36 +64,19 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract

internal static ExpandedRepo ExtractRepoArchive(string repoArchiveName)
{
#if NET461
string archiveFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string expandedFolderPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

ExtractEmbeddedResource($"repos.{repoArchiveName}.7z", archiveFilePath);
ExtractEmbeddedResource($"repos.{repoArchiveName}.zip", archiveFilePath);
try
{
for (int retryCount = 0; ; retryCount++)
{
try
{
var extractor = new SevenZipExtractor(archiveFilePath);
extractor.ExtractAll(expandedFolderPath);
return new ExpandedRepo(expandedFolderPath);
}
catch (System.ComponentModel.Win32Exception) when (retryCount < 2)
{
}
}
System.IO.Compression.ZipFile.ExtractToDirectory(archiveFilePath, expandedFolderPath);
return new ExpandedRepo(expandedFolderPath);
}
finally
{
if (File.Exists(archiveFilePath))
{
File.Delete(archiveFilePath);
}
File.Delete(archiveFilePath);
}
#else
throw new PlatformNotSupportedException();
#endif
}

internal class ExpandedRepo : IDisposable
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit ed2759e

Please sign in to comment.