Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Remove more dead code & missed excl code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 23, 2023
1 parent e77504a commit f3d7b12
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 85 deletions.
3 changes: 3 additions & 0 deletions src/Squirrel.Packaging.Windows/AuthenticodeTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static bool IsTrusted(string fileName)
}
}

[ExcludeFromCodeCoverage]
internal struct WINTRUST_FILE_INFO : IDisposable
{
public WINTRUST_FILE_INFO(string fileName, Guid subject)
Expand Down Expand Up @@ -135,6 +136,7 @@ enum UIContext

[StructLayout(LayoutKind.Sequential)]

[ExcludeFromCodeCoverage]
internal struct WINTRUST_DATA : IDisposable
{
public WINTRUST_DATA(WINTRUST_FILE_INFO fileInfo)
Expand Down Expand Up @@ -193,6 +195,7 @@ void Dispose(bool disposing)
}
}

[ExcludeFromCodeCoverage]
internal sealed class UnmanagedPointer : IDisposable
{
IntPtr m_ptr;
Expand Down
19 changes: 0 additions & 19 deletions src/Squirrel.Packaging/HelperFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,3 @@ protected static string InvokeAndThrowIfNonZero(string exePath, IEnumerable<stri
return result.StdOutput;
}
}

public class ProcessFailedException : Exception
{
public string Command { get; }
public string StdOutput { get; }

public ProcessFailedException(string command, string stdOutput)
: base($"Command failed:\n{command}\n\nOutput was:\n{stdOutput}")
{
Command = command;
StdOutput = stdOutput;
}

public static void ThrowIfNonZero((int ExitCode, string StdOutput, string Command) result)
{
if (result.ExitCode != 0)
throw new ProcessFailedException(result.Command, result.StdOutput);
}
}
23 changes: 23 additions & 0 deletions src/Squirrel.Packaging/ProcessFailedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Diagnostics.CodeAnalysis;

namespace Squirrel.Packaging;

[ExcludeFromCodeCoverage]
public class ProcessFailedException : Exception
{
public string Command { get; }
public string StdOutput { get; }

public ProcessFailedException(string command, string stdOutput)
: base($"Command failed:\n{command}\n\nOutput was:\n{stdOutput}")
{
Command = command;
StdOutput = stdOutput;
}

public static void ThrowIfNonZero((int ExitCode, string StdOutput, string Command) result)
{
if (result.ExitCode != 0)
throw new ProcessFailedException(result.Command, result.StdOutput);
}
}
66 changes: 0 additions & 66 deletions src/Squirrel/Compression/DeltaPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,72 +23,6 @@ public DeltaPackage(ILogger logger, string baseTempDir = null)
_baseTempDir = baseTempDir ?? Utility.GetDefaultTempBaseDirectory();
}

public string ApplyDeltaPackage(string basePackageZip, string deltaPackageZip, string outputFile, Action<int> progress = null)
{
progress = progress ?? (x => { });

if (deltaPackageZip is null) throw new ArgumentNullException(nameof(deltaPackageZip));
if (String.IsNullOrEmpty(outputFile)) throw new ArgumentNullException(nameof(outputFile));
if (File.Exists(outputFile)) throw new ArgumentException("File already exists", nameof(outputFile));

using (Utility.GetTempDirectory(out var deltaPath, _baseTempDir))
using (Utility.GetTempDirectory(out var workingPath, _baseTempDir)) {
EasyZip.ExtractZipToDirectory(_log, deltaPackageZip, deltaPath);
progress(25);

EasyZip.ExtractZipToDirectory(_log, basePackageZip, workingPath);
progress(50);

var pathsVisited = new List<string>();

var deltaPathRelativePaths = new DirectoryInfo(deltaPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(deltaPath + Path.DirectorySeparatorChar, ""))
.ToArray();

// Apply all of the .diff files
deltaPathRelativePaths
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".shasum", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase) ||
!deltaPathRelativePaths.Contains(x.Replace(".diff", ".bsdiff")))
.ForEach(file => {
pathsVisited.Add(Regex.Replace(file, @"\.(bs)?diff$", "").ToLowerInvariant());
applyDiffToFile(deltaPath, file, workingPath);
});

progress(75);

// Delete all of the files that were in the old package but
// not in the new one.
new DirectoryInfo(workingPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(workingPath + Path.DirectorySeparatorChar, "").ToLowerInvariant())
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase) && !pathsVisited.Contains(x))
.ForEach(x => {
_log.Info($"{x} was in old package but not in new one, deleting");
File.Delete(Path.Combine(workingPath, x));
});

progress(80);

// Update all the files that aren't in 'lib' with the delta
// package's versions (i.e. the nuspec file, etc etc).
deltaPathRelativePaths
.Where(x => !x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.ForEach(x => {
_log.Info($"Updating metadata file: {x}");
File.Copy(Path.Combine(deltaPath, x), Path.Combine(workingPath, x), true);
});

_log.Info($"Repacking into full package: {outputFile}");

EasyZip.CreateZipFromDirectory(_log, outputFile, workingPath);

progress(100);
}

return outputFile;
}

public void ApplyDeltaPackageFast(string workingPath, string deltaPackageZip, Action<int> progress = null)
{
progress = progress ?? (x => { });
Expand Down
4 changes: 4 additions & 0 deletions test/TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<ProjectReference Include="..\..\src\Squirrel\Squirrel.csproj" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage" />
</ItemGroup>

</Project>

0 comments on commit f3d7b12

Please sign in to comment.