@joebigelow / wix-1 / commits / e8030ca1

Fix naming of file in a merge module's cabinet

The file was stored in the merge module's cabinet with plain FileId, without the modularization GUID. This change fixes the cabinet builder so that it adds the modularization GUID when creating the cabinet.

Rob Mensching committed May 22, 2020 at 14:47 UTC e8030ca17ff96a794a3fecd66bb01b81581a5451
7 files changed +47 -22
src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+4 -3
@@ -134,7 +134,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
134 bool compressed;
135 bool longNames;
136 int installerVersion;
137 - string modularizationGuid;
137 + string modularizationSuffix;
138 {
139 var command = new BindSummaryInfoCommand(section);
140 command.Execute();
@@ -142,7 +142,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
142 compressed = command.Compressed;
143 longNames = command.LongNames;
144 installerVersion = command.InstallerVersion;
145 - modularizationGuid = command.ModularizationGuid;
145 + modularizationSuffix = command.ModularizationSuffix;
146 }
147
148 // Add binder variables for all properties.
@@ -362,7 +362,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
362 // Modularize identifiers.
363 if (OutputType.Module == output.Type)
364 {
365 - var command = new ModularizeCommand(output, modularizationGuid, section.Tuples.OfType<WixSuppressModularizationTuple>());
365 + var command = new ModularizeCommand(output, modularizationSuffix, section.Tuples.OfType<WixSuppressModularizationTuple>());
366 command.Execute();
367 }
368 else if (output.Type == OutputType.Patch)
@@ -448,6 +448,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
448 command.BackendExtensions = this.BackendExtensions;
449 command.LayoutDirectory = layoutDirectory;
450 command.Compressed = compressed;
451 + command.ModularizationSuffix = modularizationSuffix;
452 command.FileRowsByCabinet = filesByCabinetMedia;
453 command.ResolveMedia = this.ResolveMedia;
454 command.TableDefinitions = tableDefinitions;
src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs
+3 -3
@@ -35,14 +35,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind
35 /// <summary>
36 /// Modularization guid, or null if the output is not a module.
37 /// </summary>
38 - public string ModularizationGuid { get; private set; }
38 + public string ModularizationSuffix { get; private set; }
39
40 public void Execute()
41 {
42 this.Compressed = false;
43 this.LongNames = false;
44 this.InstallerVersion = 0;
45 - this.ModularizationGuid = null;
45 + this.ModularizationSuffix = null;
46
47 var foundCreateDataTime = false;
48 var foundLastSaveDataTime = false;
@@ -71,7 +71,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
71
72 if (SectionType.Module == this.Section.Type)
73 {
74 - this.ModularizationGuid = packageCode.Substring(1, 36).Replace('-', '_');
74 + this.ModularizationSuffix = "." + packageCode.Substring(1, 36).Replace('-', '_');
75 }
76 else if ("*" == packageCode)
77 {
src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs
+2 -2
@@ -166,8 +166,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
166
167 var files = cabinetWorkItem.FileFacades
168 .Select(facade => facade.Hash == null ?
169 - new CabinetCompressFile(facade.SourcePath, facade.Id) :
170 - new CabinetCompressFile(facade.SourcePath, facade.Id, facade.Hash.HashPart1, facade.Hash.HashPart2, facade.Hash.HashPart3, facade.Hash.HashPart4))
169 + new CabinetCompressFile(facade.SourcePath, facade.Id + cabinetWorkItem.ModularizationSuffix) :
170 + new CabinetCompressFile(facade.SourcePath, facade.Id + cabinetWorkItem.ModularizationSuffix, facade.Hash.HashPart1, facade.Hash.HashPart2, facade.Hash.HashPart3, facade.Hash.HashPart4))
171 .ToList();
172
173 var cab = new Cabinet(cabinetPath);
src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs
+7
@@ -25,9 +25,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
25 /// <param name="compressionLevel">The compression level of the cabinet.</param>
26 /// <param name="binderFileManager">The binder file manager.</param>
27 public CabinetWorkItem(IEnumerable<FileFacade> fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel /*, BinderFileManager binderFileManager*/)
28 + public CabinetWorkItem(IEnumerable<FileFacade> fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel, string modularizationSuffix /*, BinderFileManager binderFileManager*/)
29 {
30 this.cabinetFile = cabinetFile;
31 this.compressionLevel = compressionLevel;
32 + this.ModularizationSuffix = modularizationSuffix;
33 this.FileFacades = fileFacades;
34 //this.binderFileManager = binderFileManager;
35 this.maxThreshold = maxThreshold;
@@ -51,6 +53,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
53 get { return this.compressionLevel; }
54 }
55
56 + /// <summary>
57 + /// Gets the modularization suffix used when building a Merge Module.
58 + /// </summary>
59 + public string ModularizationSuffix { get; }
60 +
61 /// <summary>
62 /// Gets the collection of files in this cabinet.
63 /// </summary>
src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs
+4 -3
@@ -75,6 +75,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
75
76 public bool Compressed { private get; set; }
77
78 + public string ModularizationSuffix { private get; set; }
79 +
80 public Dictionary<MediaTuple, IEnumerable<FileFacade>> FileRowsByCabinet { private get; set; }
81
82 public Func<MediaTuple, string, string, string> ResolveMedia { private get; set; }
@@ -214,9 +216,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
216 // create a cabinet work item if it's not being skipped
217 if (CabinetBuildOption.BuildAndCopy == resolvedCabinet.BuildOption || CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption)
218 {
217 - int maxThreshold = 0; // default to the threshold for best smartcabbing (makes smallest cabinet).
218 -
219 - cabinetWorkItem = new CabinetWorkItem(fileFacades, resolvedCabinet.Path, maxThreshold, compressionLevel/*, this.FileManager*/);
219 + // Default to the threshold for best smartcabbing (makes smallest cabinet).
220 + cabinetWorkItem = new CabinetWorkItem(fileFacades, resolvedCabinet.Path, maxThreshold: 0, compressionLevel, this.ModularizationSuffix /*, this.FileManager*/);
221 }
222 else // reuse the cabinet from the cabinet cache.
223 {
src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs
+9 -10
@@ -15,10 +15,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind
15
16 internal class ModularizeCommand
17 {
18 - public ModularizeCommand(WindowsInstallerData output, string modularizationGuid, IEnumerable<WixSuppressModularizationTuple> suppressTuples)
18 + public ModularizeCommand(WindowsInstallerData output, string modularizationSuffix, IEnumerable<WixSuppressModularizationTuple> suppressTuples)
19 {
20 this.Output = output;
21 - this.ModularizationGuid = modularizationGuid;
21 + this.ModularizationSuffix = modularizationSuffix;
22
23 // Gather all the unique suppress modularization identifiers.
24 this.SuppressModularizationIdentifiers = new HashSet<string>(suppressTuples.Select(s => s.Id.Id));
@@ -26,7 +26,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
26
27 private WindowsInstallerData Output { get; }
28
29 - private string ModularizationGuid { get; }
29 + private string ModularizationSuffix { get; }
30
31 private HashSet<string> SuppressModularizationIdentifiers { get; }
32
@@ -129,7 +129,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
129 // if we're not supposed to suppress modularization of this identifier
130 if (!this.SuppressModularizationIdentifiers.Contains(fieldData))
131 {
132 - fieldData = String.Concat(fieldData, ".", this.ModularizationGuid);
132 + fieldData = String.Concat(fieldData, this.ModularizationSuffix);
133 }
134 break;
135
@@ -178,8 +178,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
178 var identifier = group.Value;
179 if (!WindowsInstallerStandard.IsStandardProperty(identifier) && !this.SuppressModularizationIdentifiers.Contains(identifier))
180 {
181 - sb.Insert(group.Index + group.Length, '.');
182 - sb.Insert(group.Index + group.Length + 1, this.ModularizationGuid);
181 + sb.Insert(group.Index + group.Length, this.ModularizationSuffix);
182 }
183 }
184 }
@@ -193,7 +192,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
192 if (!this.SuppressModularizationIdentifiers.Contains(fieldData) &&
193 0 < fieldData.Length && !Char.IsDigit(fieldData, 0))
194 {
196 - fieldData = String.Concat(fieldData, ".", this.ModularizationGuid);
195 + fieldData = String.Concat(fieldData, this.ModularizationSuffix);
196 }
197 break;
198
@@ -203,11 +202,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
202 var start = fieldData.LastIndexOf(".", StringComparison.Ordinal);
203 if (-1 == start)
204 {
206 - fieldData = String.Concat(fieldData, ".", this.ModularizationGuid);
205 + fieldData = String.Concat(fieldData, this.ModularizationSuffix);
206 }
207 else
208 {
210 - fieldData = String.Concat(fieldData.Substring(0, start), ".", this.ModularizationGuid, fieldData.Substring(start));
209 + fieldData = String.Concat(fieldData.Substring(0, start), this.ModularizationSuffix, fieldData.Substring(start));
210 }
211 }
212 break;
@@ -218,7 +217,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
217 {
218 if (!String.IsNullOrEmpty(keys[i]))
219 {
221 - keys[i] = String.Concat(keys[i], ".", this.ModularizationGuid);
220 + keys[i] = String.Concat(keys[i], this.ModularizationSuffix);
221 }
222 }
223
src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
+18 -1
@@ -346,15 +346,32 @@ namespace WixToolsetTest.CoreIntegration
346
347 result.AssertSuccess();
348
349 - Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.msm")));
349 + var msmPath = Path.Combine(intermediateFolder, @"bin\test.msm");
350 + Assert.True(File.Exists(msmPath));
351 Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.wixpdb")));
352
353 var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"bin\test.wixpdb"));
354 var section = intermediate.Sections.Single();
355
356 var fileTuple = section.Tuples.OfType<FileTuple>().Single();
357 + Assert.Equal("filyIq8rqcxxf903Hsn5K9L0SWV73g", fileTuple.Id.Id);
358 Assert.Equal(Path.Combine(folder, @"data\test.txt"), fileTuple[FileTupleFields.Source].AsPath().Path);
359 Assert.Equal(@"test.txt", fileTuple[FileTupleFields.Source].PreviousValue.AsPath().Path);
360 +
361 + var data = WindowsInstallerData.Load(Path.Combine(intermediateFolder, @"bin\test.wixpdb"));
362 + var fileRows = data.Tables["File"].Rows;
363 + Assert.Equal(new[]
364 + {
365 + "filyIq8rqcxxf903Hsn5K9L0SWV73g.243FB739_4D05_472F_9CFB_EF6B1017B6DE"
366 + }, fileRows.Select(r => r.FieldAsString(0)).ToArray());
367 +
368 + var cabPath = Path.Combine(intermediateFolder, "msm-test.cab");
369 + Query.ExtractStream(msmPath, "MergeModule.CABinet", cabPath);
370 + var files = Query.GetCabinetFiles(cabPath);
371 + Assert.Equal(new[]
372 + {
373 + "filyIq8rqcxxf903Hsn5K9L0SWV73g.243FB739_4D05_472F_9CFB_EF6B1017B6DE"
374 + }, files.Select(f => Path.Combine(f.Path, f.Name)).ToArray());
375 }
376 }
377