@joebigelow / wix-1 / commits / 9ab4a1c8

Fix duplicate keys from inline subdirectories.

Fixes https://github.com/wixtoolset/issues/issues/7459.

Bob Arnson committed May 17, 2023 at 18:14 UTC 9ab4a1c8ed3ca04858ce31402e64839dc3e46edc
3 files changed +36 -11
src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
+10 -4
@@ -1319,6 +1319,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1319 {
1320 var directory = symbol.Name.Trim(PathSeparatorChars);
1321 var parentDir = symbol.ParentDirectoryRef ?? (symbol.Id.Id == "TARGETDIR" ? null : "TARGETDIR");
1322 + var directoryRows = this.Data.TryGetTable("Directory", out var table) ? table.Rows.ToDictionary(row => row.FieldAsString(0)) : new Dictionary<string, Row>();
1323
1324 var start = 0;
1325 var end = directory.IndexOfAny(PathSeparatorChars);
@@ -1335,10 +1336,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1336 var id = this.BackendHelper.GenerateIdentifier("d", symbol.ParentDirectoryRef, path);
1337 var shortnameSubdirectory = this.BackendHelper.IsValidShortFilename(subdirectoryName, false) ? null : this.CreateShortName(subdirectoryName, false, "Directory", symbol.ParentDirectoryRef);
1338
1338 - var subdirectoryRow = this.CreateRow(symbol, "Directory");
1339 - subdirectoryRow[0] = id;
1340 - subdirectoryRow[1] = parentDir;
1341 - subdirectoryRow[2] = CreateMsiFilename(shortnameSubdirectory, subdirectoryName);
1339 + if (!directoryRows.ContainsKey(id))
1340 + {
1341 + var subdirectoryRow = this.CreateRow(symbol, "Directory");
1342 + subdirectoryRow[0] = id;
1343 + subdirectoryRow[1] = parentDir;
1344 + subdirectoryRow[2] = CreateMsiFilename(shortnameSubdirectory, subdirectoryName);
1345 +
1346 + directoryRows.Add(id, subdirectoryRow);
1347 + }
1348
1349 parentDir = id;
1350 }
src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs
+2 -1
@@ -170,7 +170,8 @@ namespace WixToolsetTest.CoreIntegration
170 var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList();
171 WixAssert.CompareLineByLine(new[]
172 {
173 - "dZsSsu81KcG46xXTwc4mTSZO5Zx4:INSTALLFOLDER:dupe",
173 + @"d6axmdFGwwNJUBTBpSSKcI7uWXo8:INSTALLFOLDER:path\to\path1",
174 + @"dQ9mCRk.rZXStHc.ILz66dIhE0FI:INSTALLFOLDER:path\to\path2",
175 "INSTALLFOLDER:ProgramFiles6432Folder:MsiPackage",
176 "ProgramFiles6432Folder:ProgramFiles64Folder:.",
177 "ProgramFiles64Folder:TARGETDIR:PFiles64",
src/wix/test/WixToolsetTest.CoreIntegration/TestData/DuplicateDir/DuplicateDir.wxs
+24 -6
@@ -2,23 +2,41 @@
2 <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <ComponentGroup Id="ProductComponents">
5 - <ComponentGroupRef Id="GroupA" />
6 - <ComponentGroupRef Id="GroupB" />
5 + <ComponentGroupRef Id="GroupA1" />
6 + <ComponentGroupRef Id="GroupA2" />
7 + <ComponentGroupRef Id="GroupB1" />
8 + <ComponentGroupRef Id="GroupB2" />
9 </ComponentGroup>
10 </Fragment>
11
12 <Fragment>
11 - <ComponentGroup Id="GroupA" Directory="INSTALLFOLDER" Subdirectory="dupe">
13 + <ComponentGroup Id="GroupA1" Directory="INSTALLFOLDER" Subdirectory="path\to\path1">
14 <Component>
13 - <File Name="a.txt" Source="test.txt" />
15 + <File Name="a1.txt" Source="test.txt" />
16 </Component>
17 </ComponentGroup>
18 </Fragment>
19
20 <Fragment>
19 - <ComponentGroup Id="GroupB" Directory="INSTALLFOLDER" Subdirectory="dupe">
21 + <ComponentGroup Id="GroupB1" Directory="INSTALLFOLDER" Subdirectory="path\to\path1">
22 <Component>
21 - <File Name="b.txt" Source="test.txt" />
23 + <File Name="b1.txt" Source="test.txt" />
24 + </Component>
25 + </ComponentGroup>
26 + </Fragment>
27 +
28 + <Fragment>
29 + <ComponentGroup Id="GroupA2" Directory="INSTALLFOLDER" Subdirectory="path\to\path2">
30 + <Component>
31 + <File Name="a2.txt" Source="test.txt" />
32 + </Component>
33 + </ComponentGroup>
34 + </Fragment>
35 +
36 + <Fragment>
37 + <ComponentGroup Id="GroupB2" Directory="INSTALLFOLDER" Subdirectory="path\to\path2">
38 + <Component>
39 + <File Name="b2.txt" Source="test.txt" />
40 </Component>
41 </ComponentGroup>
42 </Fragment>