diff options
author | Bob Arnson <bob@firegiant.com> | 2024-09-21 22:55:19 -0400 |
---|---|---|
committer | Bob Arnson <bob@firegiant.com> | 2024-09-21 22:55:19 -0400 |
commit | 372d892a62e6d886b38dbfd8bb6db3d06a12ce88 (patch) | |
tree | bfde6b0b2221781679278d560507f93271dbff33 | |
parent | dd2fe20d9fe58719445411524bd730495140d02f (diff) | |
download | wix-bob/wixbug_8740.tar.gz wix-bob/wixbug_8740.tar.bz2 wix-bob/wixbug_8740.zip |
Handle rooted file harvesting.bob/wixbug_8740
Also don't fail-fast when directory doesn't exist.
Fixes https://github.com/wixtoolset/issues/issues/8740.
3 files changed, 56 insertions, 52 deletions
diff --git a/src/wix/WixToolset.Core/HarvestFilesCommand.cs b/src/wix/WixToolset.Core/HarvestFilesCommand.cs index a8c716d0..6927f741 100644 --- a/src/wix/WixToolset.Core/HarvestFilesCommand.cs +++ b/src/wix/WixToolset.Core/HarvestFilesCommand.cs | |||
@@ -52,28 +52,19 @@ namespace WixToolset.Core | |||
52 | 52 | ||
53 | var resolvedFiles = Enumerable.Empty<WildcardFile>(); | 53 | var resolvedFiles = Enumerable.Empty<WildcardFile>(); |
54 | 54 | ||
55 | try | 55 | var included = this.GetWildcardFiles(harvestFile, inclusions); |
56 | { | 56 | var excluded = this.GetWildcardFiles(harvestFile, exclusions); |
57 | var included = this.GetWildcardFiles(harvestFile, inclusions); | ||
58 | var excluded = this.GetWildcardFiles(harvestFile, exclusions); | ||
59 | 57 | ||
60 | foreach (var excludedFile in excluded) | 58 | foreach (var excludedFile in excluded) |
61 | { | 59 | { |
62 | this.Messaging.Write(OptimizerVerboses.ExcludedFile(harvestFile.SourceLineNumbers, excludedFile.Path)); | 60 | this.Messaging.Write(OptimizerVerboses.ExcludedFile(harvestFile.SourceLineNumbers, excludedFile.Path)); |
63 | } | 61 | } |
64 | 62 | ||
65 | resolvedFiles = included.Except(excluded, comparer).ToList(); | 63 | resolvedFiles = included.Except(excluded, comparer).ToList(); |
66 | 64 | ||
67 | if (!resolvedFiles.Any()) | 65 | if (!resolvedFiles.Any()) |
68 | { | ||
69 | this.Messaging.Write(OptimizerWarnings.ZeroFilesHarvested(harvestFile.SourceLineNumbers)); | ||
70 | } | ||
71 | } | ||
72 | catch (DirectoryNotFoundException e) | ||
73 | { | 66 | { |
74 | this.Messaging.Write(OptimizerWarnings.ExpectedDirectory(harvestFile.SourceLineNumbers, e.Message)); | 67 | this.Messaging.Write(OptimizerWarnings.ZeroFilesHarvested(harvestFile.SourceLineNumbers)); |
75 | |||
76 | return; | ||
77 | } | 68 | } |
78 | 69 | ||
79 | foreach (var fileByRecursiveDir in resolvedFiles.GroupBy(resolvedFile => resolvedFile.RecursiveDir, resolvedFile => resolvedFile.Path)) | 70 | foreach (var fileByRecursiveDir in resolvedFiles.GroupBy(resolvedFile => resolvedFile.RecursiveDir, resolvedFile => resolvedFile.Path)) |
@@ -139,48 +130,53 @@ namespace WixToolset.Core | |||
139 | 130 | ||
140 | var files = new List<WildcardFile>(); | 131 | var files = new List<WildcardFile>(); |
141 | 132 | ||
142 | foreach (var pattern in patterns) | 133 | try |
143 | { | 134 | { |
144 | // Resolve bind paths, if any, which might result in multiple directories. | 135 | foreach (var pattern in patterns) |
145 | foreach (var path in this.ResolveBindPaths(sourceLineNumbers, pattern)) | ||
146 | { | 136 | { |
147 | var sourceDirectory = String.IsNullOrEmpty(sourcePath) ? Path.GetDirectoryName(sourceLineNumbers.FileName) : sourcePath; | 137 | // Resolve bind paths, if any, which might result in multiple directories. |
148 | var recursive = path.IndexOf("**") >= 0; | 138 | foreach (var path in this.ResolveBindPaths(sourceLineNumbers, pattern)) |
149 | var filePortion = Path.GetFileName(path); | ||
150 | var directoryPortion = Path.GetDirectoryName(path); | ||
151 | |||
152 | if (directoryPortion?.EndsWith(@"\**") == true) | ||
153 | { | 139 | { |
154 | directoryPortion = directoryPortion.Substring(0, directoryPortion.Length - 3); | 140 | var sourceDirectory = String.IsNullOrEmpty(sourcePath) ? Path.GetDirectoryName(sourceLineNumbers.FileName) : sourcePath; |
155 | } | 141 | var recursive = path.IndexOf("**") >= 0; |
142 | var filePortion = Path.GetFileName(path); | ||
143 | var directoryPortion = Path.GetDirectoryName(path).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); | ||
156 | 144 | ||
157 | var recursiveDirOffset = directoryPortion.Length + 1; | 145 | if (directoryPortion?.EndsWith(@"\**") == true) |
146 | { | ||
147 | directoryPortion = directoryPortion.Substring(0, directoryPortion.Length - 3); | ||
148 | } | ||
158 | 149 | ||
159 | if (directoryPortion is null || directoryPortion.Length == 0 || directoryPortion == "**") | 150 | if (directoryPortion is null || directoryPortion.Length == 0 || directoryPortion == "**") |
160 | { | 151 | { |
161 | directoryPortion = sourceDirectory; | 152 | directoryPortion = sourceDirectory; |
162 | recursiveDirOffset = sourceDirectory.Length + 1; | ||
163 | 153 | ||
164 | } | 154 | } |
165 | else if (!Path.IsPathRooted(directoryPortion)) | 155 | else if (!Path.IsPathRooted(directoryPortion)) |
166 | { | 156 | { |
167 | directoryPortion = Path.Combine(sourceDirectory, directoryPortion); | 157 | directoryPortion = Path.Combine(sourceDirectory, directoryPortion); |
168 | recursiveDirOffset = directoryPortion.Length + 1; | 158 | } |
169 | } | ||
170 | 159 | ||
171 | var foundFiles = Directory.EnumerateFiles(directoryPortion, filePortion, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); | 160 | var recursiveDirOffset = directoryPortion.Length + 1; |
172 | 161 | ||
173 | foreach (var foundFile in foundFiles) | 162 | var foundFiles = Directory.EnumerateFiles(directoryPortion, filePortion, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); |
174 | { | 163 | |
175 | var recursiveDir = Path.GetDirectoryName(foundFile.Substring(recursiveDirOffset)); | 164 | foreach (var foundFile in foundFiles) |
176 | files.Add(new WildcardFile() | ||
177 | { | 165 | { |
178 | RecursiveDir = recursiveDir, | 166 | var recursiveDir = Path.GetDirectoryName(foundFile.Substring(recursiveDirOffset)); |
179 | Path = foundFile, | 167 | files.Add(new WildcardFile() |
180 | }); | 168 | { |
169 | RecursiveDir = recursiveDir, | ||
170 | Path = foundFile, | ||
171 | }); | ||
172 | } | ||
181 | } | 173 | } |
182 | } | 174 | } |
183 | } | 175 | } |
176 | catch (DirectoryNotFoundException e) | ||
177 | { | ||
178 | this.Messaging.Write(OptimizerWarnings.ExpectedDirectory(harvestFile.SourceLineNumbers, e.Message)); | ||
179 | } | ||
184 | 180 | ||
185 | return files; | 181 | return files; |
186 | } | 182 | } |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs index 7da47f6b..e189c42d 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs | |||
@@ -48,7 +48,9 @@ namespace WixToolsetTest.CoreIntegration | |||
48 | Assert.Equal(new[] | 48 | Assert.Equal(new[] |
49 | { | 49 | { |
50 | 8601, | 50 | 8601, |
51 | 8600, | ||
51 | 8601, | 52 | 8601, |
53 | 8600, | ||
52 | }, messages); | 54 | }, messages); |
53 | }); | 55 | }); |
54 | } | 56 | } |
@@ -272,7 +274,11 @@ namespace WixToolsetTest.CoreIntegration | |||
272 | @"flsCgt3Noa1VJHlHG5HOVjD5vdJm5Q=PFiles\MsiPackage\files2_sub3\FileName.Extension", | 274 | @"flsCgt3Noa1VJHlHG5HOVjD5vdJm5Q=PFiles\MsiPackage\files2_sub3\FileName.Extension", |
273 | }; | 275 | }; |
274 | 276 | ||
275 | Build("StandardDirectory.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected)); | 277 | Build("StandardDirectory.wxs", (msiPath, result) => |
278 | { | ||
279 | result.AssertSuccess(); | ||
280 | AssertFileIdsAndTargetPaths(msiPath, expected); | ||
281 | }, warningsAsErrors: false); | ||
276 | } | 282 | } |
277 | 283 | ||
278 | [Fact] | 284 | [Fact] |
@@ -319,7 +325,7 @@ namespace WixToolsetTest.CoreIntegration | |||
319 | Assert.Equal(sortedExpected, actual); | 325 | Assert.Equal(sortedExpected, actual); |
320 | } | 326 | } |
321 | 327 | ||
322 | private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, params string[] additionalCommandLineArguments) | 328 | private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, bool warningsAsErrors = true, params string[] additionalCommandLineArguments) |
323 | { | 329 | { |
324 | var folder = TestData.Get("TestData", "HarvestFiles"); | 330 | var folder = TestData.Get("TestData", "HarvestFiles"); |
325 | 331 | ||
@@ -346,7 +352,7 @@ namespace WixToolsetTest.CoreIntegration | |||
346 | arguments.AddRange(additionalCommandLineArguments); | 352 | arguments.AddRange(additionalCommandLineArguments); |
347 | } | 353 | } |
348 | 354 | ||
349 | var result = WixRunner.Execute(arguments.ToArray()); | 355 | var result = WixRunner.Execute(warningsAsErrors, arguments.ToArray()); |
350 | 356 | ||
351 | tester(msiPath, result); | 357 | tester(msiPath, result); |
352 | } | 358 | } |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/StandardDirectory.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/StandardDirectory.wxs index 1838ed66..8b30e118 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/StandardDirectory.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/HarvestFiles/StandardDirectory.wxs | |||
@@ -5,7 +5,9 @@ | |||
5 | <StandardDirectory Id="ProgramFiles6432Folder"> | 5 | <StandardDirectory Id="ProgramFiles6432Folder"> |
6 | <!-- Relies on default-feature feature to include naked files in package. --> | 6 | <!-- Relies on default-feature feature to include naked files in package. --> |
7 | <Files Subdirectory="MsiPackage" Include="files1\**" /> | 7 | <Files Subdirectory="MsiPackage" Include="files1\**" /> |
8 | <Files Subdirectory="MsiPackage" Include="files2\**" /> | 8 | <Files Subdirectory="MsiPackage" Include="files2\**"> |
9 | <Exclude Files="notfound\**" /> | ||
10 | </Files> | ||
9 | </StandardDirectory> | 11 | </StandardDirectory> |
10 | </Package> | 12 | </Package> |
11 | </Wix> | 13 | </Wix> |