From 3f1d990939949c1fd8ae01dc8f5b0f7d6c95feb9 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Sun, 11 Feb 2024 18:46:20 +0000 Subject: [PATCH] Clean up formatting, make more rigid for #24 --- src/Velopack/Compression/DeltaPackage.cs | 12 +++---- .../WindowsPackTests.cs | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Velopack/Compression/DeltaPackage.cs b/src/Velopack/Compression/DeltaPackage.cs index 036cccb2..e75e7b78 100644 --- a/src/Velopack/Compression/DeltaPackage.cs +++ b/src/Velopack/Compression/DeltaPackage.cs @@ -38,14 +38,14 @@ namespace Velopack.Compression var deltaPathRelativePaths = new DirectoryInfo(deltaPath).GetAllFilesRecursively() .Select(x => x.FullName.Replace(deltaPath + Path.DirectorySeparatorChar, "")) .ToArray(); - + // Apply all of the .diff files var files = deltaPathRelativePaths .Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase)) .Where(x => !x.EndsWith(".shasum", StringComparison.InvariantCultureIgnoreCase)) .Where(x => DIFF_SUFFIX.IsMatch(x)) .ToArray(); - + for (var index = 0; index < files.Length; index++) { var file = files[index]; pathsVisited.Add(DIFF_SUFFIX.Replace(file, "").ToLowerInvariant()); @@ -55,7 +55,7 @@ namespace Velopack.Compression } progress(80); - + // Delete all of the files that were in the old package but // not in the new one. new DirectoryInfo(workingPath).GetAllFilesRecursively() @@ -65,13 +65,13 @@ namespace Velopack.Compression Log.Trace($"{x} was in old package but not in new one, deleting"); File.Delete(Path.Combine(workingPath, x)); }); - + progress(85); - + // Add all of the files that are in the new package but // not in the old one. deltaPathRelativePaths - .Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase) + .Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase) && !x.EndsWith(".shasum", StringComparison.InvariantCultureIgnoreCase) && !pathsVisited.Contains(DIFF_SUFFIX.Replace(x, ""), StringComparer.InvariantCultureIgnoreCase)) .ForEach(x => { diff --git a/test/Velopack.Packaging.Tests/WindowsPackTests.cs b/test/Velopack.Packaging.Tests/WindowsPackTests.cs index 0320dad8..b8b49279 100644 --- a/test/Velopack.Packaging.Tests/WindowsPackTests.cs +++ b/test/Velopack.Packaging.Tests/WindowsPackTests.cs @@ -296,6 +296,7 @@ public class WindowsPackTests string id = "SquirrelDeltaTest"; PackTestApp(id, "1.0.0", "version 1 test", releaseDir, logger); PackTestApp(id, "2.0.0", "version 2 test", releaseDir, logger, true); + PackTestApp(id, "3.0.0", "version 3 test", releaseDir, logger); // did a zsdiff get created for our v2 update? var deltaPath = Path.Combine(releaseDir, $"{id}-2.0.0-delta.nupkg"); @@ -303,11 +304,25 @@ public class WindowsPackTests using var _2 = Utility.GetTempDirectory(out var extractDir); EasyZip.ExtractZipToDirectory(logger, deltaPath, extractDir); var extractDllDiff = Path.Combine(extractDir, "lib", "app", "testapp.dll.zsdiff"); + var extractDllShasum = Path.Combine(extractDir, "lib", "app", "testapp.dll.shasum"); Assert.True(File.Exists(extractDllDiff)); Assert.True(new FileInfo(extractDllDiff).Length > 0); + Assert.True(File.Exists(extractDllShasum)); + Assert.True(new FileInfo(extractDllShasum).Length > 0); + var extractAppDiff = Path.Combine(extractDir, "lib", "app", "testapp.exe.diff"); // not changed Assert.True(File.Exists(extractAppDiff)); Assert.True(new FileInfo(extractAppDiff).Length == 0); + var extractAppShasum = Path.Combine(extractDir, "lib", "app", "testapp.exe.shasum"); + Assert.True(File.Exists(extractAppDiff)); + Assert.True(new FileInfo(extractAppDiff).Length == 0); + + // new file should exist but not have shasum + var extractNewFile = Path.Combine(extractDir, "lib", "app", "NewFile.txt"); + Assert.True(File.Exists(extractNewFile)); + Assert.True(new FileInfo(extractDllDiff).Length > 0); + var extractNewFileShasum = Path.Combine(extractDir, "lib", "app", "NewFile.txt.shasum"); + Assert.False(File.Exists(extractNewFileShasum)); // apply delta and check package var output = Path.Combine(releaseDir, "delta.patched"); @@ -324,6 +339,23 @@ public class WindowsPackTests var f2 = File.ReadAllBytes(v2); Assert.True(new ReadOnlySpan(f1).SequenceEqual(new ReadOnlySpan(f2))); Assert.True(DeltaPackageBuilder.AreFilesEqualFast(output, v2)); + + // can apply multiple deltas, and handle add/removing files? + output = Path.Combine(releaseDir, "delta.patched2"); + var deltav3 = Path.Combine(releaseDir, $"{id}-3.0.0-delta.nupkg"); + new DeltaPatchCommandRunner(logger, new BasicConsole(logger, new DefaultPromptValueFactory(false))).Run(new DeltaPatchOptions { + BasePackage = Path.Combine(releaseDir, $"{id}-1.0.0-full.nupkg"), + OutputFile = output, + PatchFiles = new[] { new FileInfo(deltaPath), new FileInfo(deltav3) }, + }).GetAwaiterResult(); + + // are the packages the same? + Assert.True(File.Exists(output)); + var v3 = Path.Combine(releaseDir, $"{id}-3.0.0-full.nupkg"); + var f4 = File.ReadAllBytes(output); + var f5 = File.ReadAllBytes(v3); + Assert.True(new ReadOnlySpan(f4).SequenceEqual(new ReadOnlySpan(f5))); + Assert.True(DeltaPackageBuilder.AreFilesEqualFast(output, v3)); } [SkippableFact]