Skip to content

Commit

Permalink
Fix crash when adding file in patch when filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
barnson authored and robmen committed Oct 4, 2024
1 parent 1f46b69 commit 467367e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -53,6 +53,7 @@ internal bool TryGetPatchFiltersForRow(Row row, out string targetFilterId, out s

targetFilterId = patchFilter?.TargetFilterId;
updatedFilterId = patchFilter?.UpdatedFilterId;

return patchFilter != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ private bool ReduceTransform(WindowsInstallerData transform, IEnumerable<WixPatc
continue;
}

// Differ.sectionDelimiter
if (this.PatchFilterMap.TryGetPatchFiltersForRow(row, out var targetFilterId, out var updatedFilterId))
{
targetFilterIdsToKeep[targetFilterId] = row;
updatedFilterIdsToKeep[updatedFilterId] = row;
targetFilterIdsToKeep[targetFilterId ?? String.Empty] = row;
updatedFilterIdsToKeep[updatedFilterId ?? String.Empty] = row;
}
}

Expand Down Expand Up @@ -251,7 +250,7 @@ private bool ReduceTransform(WindowsInstallerData transform, IEnumerable<WixPatc
}
}

keptRows += ReduceTransformSequenceTable(sequenceList, targetFilterIdsToKeep, updatedFilterIdsToKeep, customActionTable);
keptRows += this.ReduceTransformSequenceTable(sequenceList, targetFilterIdsToKeep, updatedFilterIdsToKeep, customActionTable);

if (null != directoryTable)
{
Expand Down Expand Up @@ -333,7 +332,7 @@ private bool ReduceTransform(WindowsInstallerData transform, IEnumerable<WixPatc
}
}

keptRows += ReduceTransformSequenceTable(sequenceList, targetFilterIdsToKeep, updatedFilterIdsToKeep, customActionTable);
keptRows += this.ReduceTransformSequenceTable(sequenceList, targetFilterIdsToKeep, updatedFilterIdsToKeep, customActionTable);

// Delete tables that are empty.
var tablesToDelete = transform.Tables.Where(t => t.Rows.Count == 0).Select(t => t.Name).ToList();
Expand Down
36 changes: 32 additions & 4 deletions src/wix/test/WixToolsetTest.CoreIntegration/PatchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -452,7 +479,7 @@ public void CanBuildPatchWithRegistryFiltering()
}
}

private static string BuildMsi(string outputName, string sourceFolder, string baseFolder, string defineV, string defineA, string defineB, IEnumerable<string> bindpaths = null)
private static string BuildMsi(string outputName, string sourceFolder, string baseFolder, string defineV, string defineA, string defineB, string defineC = null, IEnumerable<string> bindpaths = null)
{
var outputPath = Path.Combine(baseFolder, Path.Combine("bin", outputName));

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is A v1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This ia A v1.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is B v1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This ia B v1.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is C, unversioned.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="~Test Package" Version="$(var.V)" Manufacturer="Example Corporation" Language="1033" UpgradeCode="7d326855-e790-4a94-8611-5351f8321fca" Compressed="yes" Scope="perMachine" ProductCode="7d326855-e790-4a94-8611-5351f8321fca">
<MediaTemplate EmbedCab="yes" />

<ComponentGroup Id="Components" Directory="INSTALLFOLDER">
<Component Id="CA">
<File Id="a.txt" Name="a.txt" Source="Av$(var.A).txt" />
</Component>

<Component Id="CB">
<File Id="b.txt" Name="b.txt" Source="Bv$(var.B).txt" />
</Component>

<?if $(C) == "TRUE" ?>
<Component Id="CC">
<File Id="c.txt" Name="c.txt" Source="C.txt" />
</Component>
<?endif?>
</ComponentGroup>
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>
<Patch
AllowRemoval="yes"
DisplayName="~Test Patch v$(var.V)"
Description="~Test Small Update Patch v$(var.V)"
MoreInfoURL="http://www.example.com/"
Manufacturer="Example Corporation"
Classification="Update">

<Media Id="1" Cabinet="foo.cab">
<PatchBaseline Id="RTM" BaselineFile="Baseline.wixpdb" UpdateFile="Update.wixpdb" />
</Media>

<PatchFamily Id='SequenceFamily' Version='$(var.V)'>
<ComponentRef Id="CC" />
</PatchFamily>
</Patch>
</Wix>

0 comments on commit 467367e

Please sign in to comment.