From 467367e3018767ca5bcbd7e49c349b4c176fd0b8 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Fri, 27 Sep 2024 18:12:11 -0400 Subject: [PATCH] Fix crash when adding file in patch when filtering --- .../Bind/PatchFilterMap.cs | 3 +- .../Bind/ReduceTransformCommand.cs | 9 +++-- .../PatchFixture.cs | 36 ++++++++++++++++--- .../PatchWithAddedFile/.data/Av1.0.0.txt | 1 + .../PatchWithAddedFile/.data/Av1.0.1.txt | 1 + .../PatchWithAddedFile/.data/Bv1.0.0.txt | 1 + .../PatchWithAddedFile/.data/Bv1.0.1.txt | 1 + .../TestData/PatchWithAddedFile/.data/C.txt | 1 + .../TestData/PatchWithAddedFile/Package.wxs | 21 +++++++++++ .../TestData/PatchWithAddedFile/Patch.wxs | 18 ++++++++++ 10 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.0.txt create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.1.txt create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.0.txt create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.1.txt create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/C.txt create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Package.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Patch.wxs diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/PatchFilterMap.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/PatchFilterMap.cs index 4822f3a5c..fe4dfde40 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/PatchFilterMap.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/PatchFilterMap.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Core.WindowsInstaller.Bind { @@ -53,6 +53,7 @@ internal bool TryGetPatchFiltersForRow(Row row, out string targetFilterId, out s targetFilterId = patchFilter?.TargetFilterId; updatedFilterId = patchFilter?.UpdatedFilterId; + return patchFilter != null; } diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/ReduceTransformCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/ReduceTransformCommand.cs index e7d936601..f10134808 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/ReduceTransformCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/ReduceTransformCommand.cs @@ -101,11 +101,10 @@ private bool ReduceTransform(WindowsInstallerData transform, IEnumerable t.Rows.Count == 0).Select(t => t.Name).ToList(); diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs index 49303df19..0ce4674d9 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs @@ -44,9 +44,9 @@ public PatchFixture() var tempFolderUpdate = Path.Combine(this.tempBaseFolder, "PatchTemplatePackage", "update"); var tempFolderUpdateNoFileChanges = Path.Combine(this.tempBaseFolder, "PatchTemplatePackage", "updatewithoutfilechanges"); - this.templateBaselinePdb = BuildMsi("Baseline.msi", this.templateSourceFolder, tempFolderBaseline, "1.0.0", "1.0.0", "1.0.0", new[] { Path.Combine(this.templateSourceFolder, ".baseline-data") }); - this.templateUpdatePdb = BuildMsi("Update.msi", this.templateSourceFolder, tempFolderUpdate, "1.0.1", "1.0.1", "1.0.1", new[] { Path.Combine(this.templateSourceFolder, ".update-data") }); - this.templateUpdateNoFilesChangedPdb = BuildMsi("Update.msi", this.templateSourceFolder, tempFolderUpdateNoFileChanges, "1.0.1", "1.0.1", "1.0.1", new[] { Path.Combine(this.templateSourceFolder, ".baseline-data") }); + this.templateBaselinePdb = BuildMsi("Baseline.msi", this.templateSourceFolder, tempFolderBaseline, "1.0.0", "1.0.0", "1.0.0", bindpaths: new[] { Path.Combine(this.templateSourceFolder, ".baseline-data") }); + this.templateUpdatePdb = BuildMsi("Update.msi", this.templateSourceFolder, tempFolderUpdate, "1.0.1", "1.0.1", "1.0.1", bindpaths: new[] { Path.Combine(this.templateSourceFolder, ".update-data") }); + this.templateUpdateNoFilesChangedPdb = BuildMsi("Update.msi", this.templateSourceFolder, tempFolderUpdateNoFileChanges, "1.0.1", "1.0.1", "1.0.1", bindpaths: new[] { Path.Combine(this.templateSourceFolder, ".baseline-data") }); } public void Dispose() @@ -81,6 +81,33 @@ public void CanBuildSimplePatchUsingWixpdbs() } } + [Fact] + public void CanBuildSimplePatchWithNewFileAndFilteringUsingWixpdbs() + { + var folder = TestData.Get(@"TestData", "PatchWithAddedFile"); + + using (var fs = new DisposableFileSystem()) + { + var tempFolder = fs.GetFolder(); + + var baselinePath = BuildMsi("Baseline.msi", folder, tempFolder, "1.0.0", "1.0.0", "1.0.0"); + var update1Path = BuildMsi("Update.msi", folder, tempFolder, "1.0.1", "1.0.1", "1.0.1", "TRUE"); + var patchPath = BuildMsp("Patch1.msp", folder, tempFolder, "1.0.1", warningsAsErrors: false); + + var doc = GetExtractPatchXml(patchPath); + WixAssert.StringEqual("{7D326855-E790-4A94-8611-5351F8321FCA}", doc.Root.Element(TargetProductCodeName).Value); + + var names = Query.GetSubStorageNames(patchPath); + WixAssert.CompareLineByLine(new[] { "#RTM.1", "RTM.1" }, names); + + var cab = Path.Combine(tempFolder, "foo.cab"); + Query.ExtractStream(patchPath, "foo.cab", cab); + + var files = Query.GetCabinetFiles(cab); + WixAssert.CompareLineByLine(new[] { "c.txt" }, files.Select(f => f.Name).ToArray()); + } + } + [Fact] public void CanBuildSimplePatchWithFileChangesUsingMsi() { @@ -452,7 +479,7 @@ public void CanBuildPatchWithRegistryFiltering() } } - private static string BuildMsi(string outputName, string sourceFolder, string baseFolder, string defineV, string defineA, string defineB, IEnumerable bindpaths = null) + private static string BuildMsi(string outputName, string sourceFolder, string baseFolder, string defineV, string defineA, string defineB, string defineC = null, IEnumerable bindpaths = null) { var outputPath = Path.Combine(baseFolder, Path.Combine("bin", outputName)); @@ -463,6 +490,7 @@ private static string BuildMsi(string outputName, string sourceFolder, string ba "-d", "V=" + defineV, "-d", "A=" + defineA, "-d", "B=" + defineB, + "-d", "C=" + defineC ?? String.Empty, "-bindpath", Path.Combine(sourceFolder, ".data"), "-intermediateFolder", Path.Combine(baseFolder, "obj"), "-o", outputPath, diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.0.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.0.txt new file mode 100644 index 000000000..6fd385bd0 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.0.txt @@ -0,0 +1 @@ +This is A v1.0.0 diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.1.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.1.txt new file mode 100644 index 000000000..b1f0bc01c --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Av1.0.1.txt @@ -0,0 +1 @@ +This ia A v1.0.1 diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.0.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.0.txt new file mode 100644 index 000000000..ece55fec6 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.0.txt @@ -0,0 +1 @@ +This is B v1.0.0 diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.1.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.1.txt new file mode 100644 index 000000000..cf3372fd6 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/Bv1.0.1.txt @@ -0,0 +1 @@ +This ia B v1.0.1 diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/C.txt b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/C.txt new file mode 100644 index 000000000..da7bfac11 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/.data/C.txt @@ -0,0 +1 @@ +This is C, unversioned. diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Package.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Package.wxs new file mode 100644 index 000000000..e4bdcd229 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Package.wxs @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Patch.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Patch.wxs new file mode 100644 index 000000000..679f0c10f --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/PatchWithAddedFile/Patch.wxs @@ -0,0 +1,18 @@ + + + + + + + + + + + +