Skip to content

Commit

Permalink
Handle directories a bit better for Files.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnson committed Mar 14, 2024
1 parent 976ac44 commit 4ffe9c6
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/wix/WixToolset.Core/HarvestFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se
{
var unusedSectionCachedInlinedDirectoryIds = new Dictionary<string, string>();

var directoryId = harvestFile.DirectoryRef;

var inclusions = harvestFile.Inclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var exclusions = harvestFile.Exclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

Expand Down Expand Up @@ -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))
Expand Down
47 changes: 36 additions & 11 deletions src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -58,7 +58,7 @@ public void DuplicateFilesSomethingSomething()
[Fact]
public void CanHarvestFilesInComponentGroup()
{
BuildQueryAssertFiles("ComponentGroup.wxs", new[]
BuildQueryAssertFiles("ComponentGroup.wxs", new[]
{
"FileName.Extension",
"test20.txt",
Expand All @@ -71,7 +71,7 @@ public void CanHarvestFilesInComponentGroup()
[Fact]
public void CanHarvestFilesInDirectory()
{
BuildQueryAssertFiles("Directory.wxs", new[]
BuildQueryAssertFiles("Directory.wxs", new[]
{
"test10.txt",
"test120.txt",
Expand Down Expand Up @@ -101,7 +101,7 @@ public void CanHarvestFilesInDirectoryRef()
[Fact]
public void CanHarvestFilesInFeature()
{
var rows = BuildAndQueryComponentAndFileTables("Feature.wxs");
var rows = BuildAndQueryComponentFileDirectoryTables("Feature.wxs");

AssertFileComponentIds(3, rows);
}
Expand All @@ -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()
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="MsiPackage" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade error message." />

<Feature Id="ProductFeature">
<ComponentGroupRef Id="Files" />
</Feature>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="MsiPackage" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Files Directory="ProgramFiles6432Folder" Subdirectory="root" Include="$(sys.SOURCEFILEDIR)\bigtree\**" />
</Package>
</Wix>
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 4ffe9c6

Please sign in to comment.