Handle directories a bit better for `Files`.
Fixes https://github.com/wixtoolset/issues/issues/8040.
Bob Arnson committed
Mar 14, 2024 at 13:51 UTC
dabcb37846e8f6da9d43984863678e9a4cf57b3e
14 files changed
+43
-15
src/wix/WixToolset.Core/HarvestFilesCommand.cs
+2
-2
@@ -45,8 +45,6 @@ namespace WixToolset.Core
45
{
46
var unusedSectionCachedInlinedDirectoryIds = new Dictionary<string, string>();
47
48
- var directoryId = harvestFile.DirectoryRef;
49
-
48
var inclusions = harvestFile.Inclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
49
var exclusions = harvestFile.Exclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
50
@@ -75,6 +73,8 @@ namespace WixToolset.Core
73
74
foreach (var fileByRecursiveDir in resolvedFiles.GroupBy(resolvedFile => resolvedFile.RecursiveDir, resolvedFile => resolvedFile.Path))
75
{
76
+ var directoryId = harvestFile.DirectoryRef;
77
+
78
var recursiveDir = fileByRecursiveDir.Key;
79
80
if (!String.IsNullOrEmpty(recursiveDir))
src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs
+36
-11
@@ -14,7 +14,7 @@ namespace WixToolsetTest.CoreIntegration
14
[Fact]
15
public void MustIncludeSomeFiles()
16
{
17
- var messages = BuildAndQueryComponentAndFileTables("BadAuthoring.wxs", isPackage: true, 10);
17
+ var messages = BuildAndQueryComponentFileDirectoryTables("BadAuthoring.wxs", isPackage: true, 10);
18
Assert.Equal(new[]
19
{
20
"10",
@@ -24,7 +24,7 @@ namespace WixToolsetTest.CoreIntegration
24
[Fact]
25
public void ZeroFilesHarvestedIsAWarning()
26
{
27
- var messages = BuildAndQueryComponentAndFileTables("ZeroFiles.wxs", isPackage: true, 8600);
27
+ var messages = BuildAndQueryComponentFileDirectoryTables("ZeroFiles.wxs", isPackage: true, 8600);
28
Assert.Equal(new[]
29
{
30
"8600",
@@ -34,7 +34,7 @@ namespace WixToolsetTest.CoreIntegration
34
[Fact]
35
public void MissingHarvestDirectoryIsAWarning()
36
{
37
- var messages = BuildAndQueryComponentAndFileTables("BadDirectory.wxs", isPackage: true, 8601);
37
+ var messages = BuildAndQueryComponentFileDirectoryTables("BadDirectory.wxs", isPackage: true, 8601);
38
Assert.Equal(new[]
39
{
40
"8601",
@@ -45,7 +45,7 @@ namespace WixToolsetTest.CoreIntegration
45
[Fact]
46
public void DuplicateFilesSomethingSomething()
47
{
48
- var messages = BuildAndQueryComponentAndFileTables("DuplicateFiles.wxs", isPackage: true, 8602);
48
+ var messages = BuildAndQueryComponentFileDirectoryTables("DuplicateFiles.wxs", isPackage: true, 8602);
49
Assert.Equal(new[]
50
{
51
"8602",
@@ -58,7 +58,7 @@ namespace WixToolsetTest.CoreIntegration
58
[Fact]
59
public void CanHarvestFilesInComponentGroup()
60
{
61
- BuildQueryAssertFiles("ComponentGroup.wxs", new[]
61
+ BuildQueryAssertFiles("ComponentGroup.wxs", new[]
62
{
63
"FileName.Extension",
64
"test20.txt",
@@ -71,7 +71,7 @@ namespace WixToolsetTest.CoreIntegration
71
[Fact]
72
public void CanHarvestFilesInDirectory()
73
{
74
- BuildQueryAssertFiles("Directory.wxs", new[]
74
+ BuildQueryAssertFiles("Directory.wxs", new[]
75
{
76
"test10.txt",
77
"test120.txt",
@@ -101,7 +101,7 @@ namespace WixToolsetTest.CoreIntegration
101
[Fact]
102
public void CanHarvestFilesInFeature()
103
{
104
- var rows = BuildAndQueryComponentAndFileTables("Feature.wxs");
104
+ var rows = BuildAndQueryComponentFileDirectoryTables("Feature.wxs");
105
106
AssertFileComponentIds(3, rows);
107
}
@@ -123,6 +123,22 @@ namespace WixToolsetTest.CoreIntegration
123
});
124
}
125
126
+ [Fact]
127
+ public void CanHarvestFilesInStraightAndCrookedTrees()
128
+ {
129
+ var rows = BuildAndQueryComponentFileDirectoryTables("CrookedTree.wxs");
130
+ var directoryRows = rows.Where(row => row.StartsWith("Directory:")).Select(d => d.Substring(10)).ToArray();
131
+
132
+ var rootDirectoryId = directoryRows.Single(r => r.EndsWith("\troot")).Split('\t')[0];
133
+
134
+ foreach (var ch in new[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'z' })
135
+ {
136
+ var directoryRow = directoryRows.Single(r => r.EndsWith($"\t{ch}"));
137
+ var parentDirectory = directoryRow.Split('\t')[1];
138
+ Assert.Equal(rootDirectoryId, parentDirectory);
139
+ }
140
+ }
141
+
142
[Fact]
143
public void CanHarvestFilesInFeatureRef()
144
{
@@ -186,7 +202,7 @@ namespace WixToolsetTest.CoreIntegration
202
[Fact]
203
public void HarvestedFilesUnderPackageWithAuthoredFeatureAreOrphaned()
204
{
189
- var messages = BuildAndQueryComponentAndFileTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267);
205
+ var messages = BuildAndQueryComponentFileDirectoryTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267);
206
Assert.Equal(new[]
207
{
208
"267",
@@ -232,14 +248,23 @@ namespace WixToolsetTest.CoreIntegration
248
249
private static void BuildQueryAssertFiles(string file, string[] expectedFileNames, bool isPackage = true, int? exitCode = null)
250
{
235
- var rows = BuildAndQueryComponentAndFileTables(file, isPackage, exitCode);
251
+ var rows = BuildAndQueryComponentFileDirectoryTables(file, isPackage, exitCode);
252
+
253
+ var fileNames = AssertFileComponentIds(expectedFileNames.Length, rows);
254
+
255
+ Assert.Equal(expectedFileNames, fileNames);
256
+ }
257
+
258
+ private static void BuildQueryDirectoryComponent(string file, string[] expectedFileNames, bool isPackage = true, int? exitCode = null)
259
+ {
260
+ var rows = BuildAndQueryComponentFileDirectoryTables(file, isPackage, exitCode);
261
262
var fileNames = AssertFileComponentIds(expectedFileNames.Length, rows);
263
264
Assert.Equal(expectedFileNames, fileNames);
265
}
266
242
- private static string[] BuildAndQueryComponentAndFileTables(string file, bool isPackage = true, int? exitCode = null)
267
+ private static string[] BuildAndQueryComponentFileDirectoryTables(string file, bool isPackage = true, int? exitCode = null)
268
{
269
var folder = TestData.Get("TestData", "HarvestFiles");
270
@@ -273,7 +298,7 @@ namespace WixToolsetTest.CoreIntegration
298
{
299
result.AssertSuccess();
300
276
- return Query.QueryDatabase(msiPath, new[] { "Component", "File" })
301
+ return Query.QueryDatabase(msiPath, new[] { "Component", "File", "Directory" })
302
.OrderBy(s => s)
303
.ToArray();
304
}
src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/ComponentGroup.wxs
-2
@@ -1,7 +1,5 @@
1
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
<Package Name="MsiPackage" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
3
- <MajorUpgrade DowngradeErrorMessage="Downgrade error message." />
4
-
3
<Feature Id="ProductFeature">
4
<ComponentGroupRef Id="Files" />
5
</Feature>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/CrookedTree.wxs
new
+5
@@ -0,0 +1,5 @@
1
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2
+ <Package Name="MsiPackage" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
3
+ <Files Directory="ProgramFiles6432Folder" Subdirectory="root" Include="$(sys.SOURCEFILEDIR)\bigtree\**" />
4
+ </Package>
5
+</Wix>