mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Remove more dead code & missed excl code coverage
This commit is contained in:
@@ -38,6 +38,7 @@ namespace Squirrel.Packaging.Windows
|
||||
}
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal struct WINTRUST_FILE_INFO : IDisposable
|
||||
{
|
||||
public WINTRUST_FILE_INFO(string fileName, Guid subject)
|
||||
@@ -135,6 +136,7 @@ namespace Squirrel.Packaging.Windows
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal struct WINTRUST_DATA : IDisposable
|
||||
{
|
||||
public WINTRUST_DATA(WINTRUST_FILE_INFO fileInfo)
|
||||
@@ -193,6 +195,7 @@ namespace Squirrel.Packaging.Windows
|
||||
}
|
||||
}
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal sealed class UnmanagedPointer : IDisposable
|
||||
{
|
||||
IntPtr m_ptr;
|
||||
|
||||
@@ -93,22 +93,3 @@ public class HelperFile
|
||||
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
src/Squirrel.Packaging/ProcessFailedException.cs
Normal file
23
src/Squirrel.Packaging/ProcessFailedException.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -23,72 +23,6 @@ namespace Squirrel.Compression
|
||||
_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 => { });
|
||||
|
||||
@@ -10,4 +10,8 @@
|
||||
<ProjectReference Include="..\..\src\Squirrel\Squirrel.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user