diff --git a/src/wix/WixToolset.Core/HarvestFilesCommand.cs b/src/wix/WixToolset.Core/HarvestFilesCommand.cs index c92de516c..4f0c2e2a0 100644 --- a/src/wix/WixToolset.Core/HarvestFilesCommand.cs +++ b/src/wix/WixToolset.Core/HarvestFilesCommand.cs @@ -45,8 +45,6 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se { var unusedSectionCachedInlinedDirectoryIds = new Dictionary(); - var directoryId = harvestFile.DirectoryRef; - var inclusions = harvestFile.Inclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var exclusions = harvestFile.Exclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); @@ -75,6 +73,8 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se foreach (var fileByRecursiveDir in resolvedFiles.GroupBy(resolvedFile => resolvedFile.RecursiveDir, resolvedFile => resolvedFile.Path)) { + var directoryId = harvestFile.DirectoryRef; + var recursiveDir = fileByRecursiveDir.Key; if (!String.IsNullOrEmpty(recursiveDir)) diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs index c9e7fb142..8bf03ebb9 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs @@ -14,7 +14,7 @@ public class HarvestFilesFixture [Fact] public void MustIncludeSomeFiles() { - var messages = BuildAndQueryComponentAndFileTables("BadAuthoring.wxs", isPackage: true, 10); + var messages = BuildAndQueryComponentFileDirectoryTables("BadAuthoring.wxs", isPackage: true, 10); Assert.Equal(new[] { "10", @@ -24,7 +24,7 @@ public void MustIncludeSomeFiles() [Fact] public void ZeroFilesHarvestedIsAWarning() { - var messages = BuildAndQueryComponentAndFileTables("ZeroFiles.wxs", isPackage: true, 8600); + var messages = BuildAndQueryComponentFileDirectoryTables("ZeroFiles.wxs", isPackage: true, 8600); Assert.Equal(new[] { "8600", @@ -34,7 +34,7 @@ public void ZeroFilesHarvestedIsAWarning() [Fact] public void MissingHarvestDirectoryIsAWarning() { - var messages = BuildAndQueryComponentAndFileTables("BadDirectory.wxs", isPackage: true, 8601); + var messages = BuildAndQueryComponentFileDirectoryTables("BadDirectory.wxs", isPackage: true, 8601); Assert.Equal(new[] { "8601", @@ -45,7 +45,7 @@ public void MissingHarvestDirectoryIsAWarning() [Fact] public void DuplicateFilesSomethingSomething() { - var messages = BuildAndQueryComponentAndFileTables("DuplicateFiles.wxs", isPackage: true, 8602); + var messages = BuildAndQueryComponentFileDirectoryTables("DuplicateFiles.wxs", isPackage: true, 8602); Assert.Equal(new[] { "8602", @@ -58,7 +58,7 @@ public void DuplicateFilesSomethingSomething() [Fact] public void CanHarvestFilesInComponentGroup() { - BuildQueryAssertFiles("ComponentGroup.wxs", new[] + BuildQueryAssertFiles("ComponentGroup.wxs", new[] { "FileName.Extension", "test20.txt", @@ -71,7 +71,7 @@ public void CanHarvestFilesInComponentGroup() [Fact] public void CanHarvestFilesInDirectory() { - BuildQueryAssertFiles("Directory.wxs", new[] + BuildQueryAssertFiles("Directory.wxs", new[] { "test10.txt", "test120.txt", @@ -101,7 +101,7 @@ public void CanHarvestFilesInDirectoryRef() [Fact] public void CanHarvestFilesInFeature() { - var rows = BuildAndQueryComponentAndFileTables("Feature.wxs"); + var rows = BuildAndQueryComponentFileDirectoryTables("Feature.wxs"); AssertFileComponentIds(3, rows); } @@ -123,6 +123,22 @@ public void CanHarvestFilesInFeatureGroup() }); } + [Fact] + public void CanHarvestFilesInStraightAndCrookedTrees() + { + var rows = BuildAndQueryComponentFileDirectoryTables("CrookedTree.wxs"); + var directoryRows = rows.Where(row => row.StartsWith("Directory:")).Select(d => d.Substring(10)).ToArray(); + + var rootDirectoryId = directoryRows.Single(r => r.EndsWith("\troot")).Split('\t')[0]; + + foreach (var ch in new[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'z' }) + { + var directoryRow = directoryRows.Single(r => r.EndsWith($"\t{ch}")); + var parentDirectory = directoryRow.Split('\t')[1]; + Assert.Equal(rootDirectoryId, parentDirectory); + } + } + [Fact] public void CanHarvestFilesInFeatureRef() { @@ -186,7 +202,7 @@ public void CanHarvestFilesWithBindPaths() [Fact] public void HarvestedFilesUnderPackageWithAuthoredFeatureAreOrphaned() { - var messages = BuildAndQueryComponentAndFileTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267); + var messages = BuildAndQueryComponentFileDirectoryTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267); Assert.Equal(new[] { "267", @@ -232,14 +248,23 @@ public void CanHarvestFilesInFiveLines() private static void BuildQueryAssertFiles(string file, string[] expectedFileNames, bool isPackage = true, int? exitCode = null) { - var rows = BuildAndQueryComponentAndFileTables(file, isPackage, exitCode); + var rows = BuildAndQueryComponentFileDirectoryTables(file, isPackage, exitCode); + + var fileNames = AssertFileComponentIds(expectedFileNames.Length, rows); + + Assert.Equal(expectedFileNames, fileNames); + } + + private static void BuildQueryDirectoryComponent(string file, string[] expectedFileNames, bool isPackage = true, int? exitCode = null) + { + var rows = BuildAndQueryComponentFileDirectoryTables(file, isPackage, exitCode); var fileNames = AssertFileComponentIds(expectedFileNames.Length, rows); Assert.Equal(expectedFileNames, fileNames); } - private static string[] BuildAndQueryComponentAndFileTables(string file, bool isPackage = true, int? exitCode = null) + private static string[] BuildAndQueryComponentFileDirectoryTables(string file, bool isPackage = true, int? exitCode = null) { var folder = TestData.Get("TestData", "HarvestFiles"); @@ -273,7 +298,7 @@ private static string[] BuildAndQueryComponentAndFileTables(string file, bool is { result.AssertSuccess(); - return Query.QueryDatabase(msiPath, new[] { "Component", "File" }) + return Query.QueryDatabase(msiPath, new[] { "Component", "File", "Directory" }) .OrderBy(s => s) .ToArray(); } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/ComponentGroup.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/ComponentGroup.wxs index 963f40a53..7755ffb10 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/ComponentGroup.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/ComponentGroup.wxs @@ -1,7 +1,5 @@ - - diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/CrookedTree.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/CrookedTree.wxs new file mode 100644 index 000000000..4f46a81a3 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/CrookedTree.wxs @@ -0,0 +1,5 @@ + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/a/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/a/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/b/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/b/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/c/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/c/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/d/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/d/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/e/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/e/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/f/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/f/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/g/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/g/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/h/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/h/file.ext new file mode 100644 index 000000000..e69de29bb diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/z/y/x/w/v/u/t/s/r/q/file.ext b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/bigtree/z/y/x/w/v/u/t/s/r/q/file.ext new file mode 100644 index 000000000..e69de29bb