Display warning when extracting bundle from Package Cache
The Package Cache contains stripped bundles which would fail extraction with an exception. Display a warning instead. Plus do a touch of code clean up. Fixes 6315
Rob Mensching committed
Mar 14, 2022 at 10:27 UTC
2a702f736a907febdd03b493437f0bad3f6732af
3 files changed
+40
-31
src/wix/WixToolset.Core.Burn/Bundles/BurnReader.cs
+25
-30
@@ -84,9 +84,9 @@ namespace WixToolset.Core.Burn.Bundles
84
}
85
86
Directory.CreateDirectory(outputDirectory);
87
- string tempCabPath = Path.Combine(tempDirectory, "ux.cab");
88
- string manifestOriginalPath = Path.Combine(outputDirectory, "0");
89
- string manifestPath = Path.Combine(outputDirectory, "manifest.xml");
87
+ var tempCabPath = Path.Combine(tempDirectory, "ux.cab");
88
+ var manifestOriginalPath = Path.Combine(outputDirectory, "0");
89
+ var manifestPath = Path.Combine(outputDirectory, "manifest.xml");
90
var uxContainerSlot = this.AttachedContainers[0];
91
92
this.binaryReader.BaseStream.Seek(this.UXAddress, SeekOrigin.Begin);
@@ -101,20 +101,20 @@ namespace WixToolset.Core.Burn.Bundles
101
Directory.CreateDirectory(Path.GetDirectoryName(manifestPath));
102
FileSystem.MoveFile(manifestOriginalPath, manifestPath);
103
104
- XmlDocument document = new XmlDocument();
104
+ var document = new XmlDocument();
105
document.Load(manifestPath);
106
- XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable);
106
+ var namespaceManager = new XmlNamespaceManager(document.NameTable);
107
namespaceManager.AddNamespace("burn", BurnCommon.BurnNamespace);
108
- XmlNodeList uxPayloads = document.SelectNodes("/burn:BurnManifest/burn:UX/burn:Payload", namespaceManager);
109
- XmlNodeList payloads = document.SelectNodes("/burn:BurnManifest/burn:Payload", namespaceManager);
108
+ var uxPayloads = document.SelectNodes("/burn:BurnManifest/burn:UX/burn:Payload", namespaceManager);
109
+ var payloads = document.SelectNodes("/burn:BurnManifest/burn:Payload", namespaceManager);
110
111
foreach (XmlNode uxPayload in uxPayloads)
112
{
113
- XmlNode sourcePathNode = uxPayload.Attributes.GetNamedItem("SourcePath");
114
- XmlNode filePathNode = uxPayload.Attributes.GetNamedItem("FilePath");
113
+ var sourcePathNode = uxPayload.Attributes.GetNamedItem("SourcePath");
114
+ var filePathNode = uxPayload.Attributes.GetNamedItem("FilePath");
115
116
- string sourcePath = Path.Combine(outputDirectory, sourcePathNode.Value);
117
- string destinationPath = Path.Combine(outputDirectory, filePathNode.Value);
116
+ var sourcePath = Path.Combine(outputDirectory, sourcePathNode.Value);
117
+ var destinationPath = Path.Combine(outputDirectory, filePathNode.Value);
118
119
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
120
FileSystem.MoveFile(sourcePath, destinationPath);
@@ -122,18 +122,18 @@ namespace WixToolset.Core.Burn.Bundles
122
123
foreach (XmlNode payload in payloads)
124
{
125
- XmlNode packagingNode = payload.Attributes.GetNamedItem("Packaging");
125
+ var packagingNode = payload.Attributes.GetNamedItem("Packaging");
126
127
- string packaging = packagingNode.Value;
127
+ var packaging = packagingNode.Value;
128
129
if (packaging.Equals("embedded", StringComparison.OrdinalIgnoreCase))
130
{
131
- XmlNode sourcePathNode = payload.Attributes.GetNamedItem("SourcePath");
132
- XmlNode filePathNode = payload.Attributes.GetNamedItem("FilePath");
133
- XmlNode containerNode = payload.Attributes.GetNamedItem("Container");
131
+ var sourcePathNode = payload.Attributes.GetNamedItem("SourcePath");
132
+ var filePathNode = payload.Attributes.GetNamedItem("FilePath");
133
+ var containerNode = payload.Attributes.GetNamedItem("Container");
134
135
- string sourcePath = sourcePathNode.Value;
136
- string destinationPath = Path.Combine(containerNode.Value, filePathNode.Value);
135
+ var sourcePath = sourcePathNode.Value;
136
+ var destinationPath = Path.Combine(containerNode.Value, filePathNode.Value);
137
138
this.attachedContainerPayloadNames.Add(new DictionaryEntry(sourcePath, destinationPath));
139
}
@@ -142,11 +142,6 @@ namespace WixToolset.Core.Burn.Bundles
142
return true;
143
}
144
145
- internal void ExtractUXContainer(string uxExtractPath, object intermediateFolder)
146
- {
147
- throw new NotImplementedException();
148
- }
149
-
145
/// <summary>
146
/// Gets each non-UX attached container from the exe and extracts its contents to the output directory.
147
/// </summary>
@@ -167,11 +162,11 @@ namespace WixToolset.Core.Burn.Bundles
162
}
163
164
Directory.CreateDirectory(outputDirectory);
170
- uint nextAddress = this.EngineSize;
171
- for (int i = 1; i < this.AttachedContainers.Count; i++)
165
+ var nextAddress = this.EngineSize;
166
+ for (var i = 1; i < this.AttachedContainers.Count; i++)
167
{
173
- ContainerSlot cntnr = this.AttachedContainers[i];
174
- string tempCabPath = Path.Combine(tempDirectory, $"a{i}.cab");
168
+ var cntnr = this.AttachedContainers[i];
169
+ var tempCabPath = Path.Combine(tempDirectory, $"a{i}.cab");
170
171
this.binaryReader.BaseStream.Seek(nextAddress, SeekOrigin.Begin);
172
using (Stream tempCab = File.Open(tempCabPath, FileMode.Create, FileAccess.Write))
@@ -185,10 +180,10 @@ namespace WixToolset.Core.Burn.Bundles
180
nextAddress += cntnr.Size;
181
}
182
188
- foreach (DictionaryEntry entry in this.attachedContainerPayloadNames)
183
+ foreach (var entry in this.attachedContainerPayloadNames)
184
{
190
- string sourcePath = Path.Combine(outputDirectory, (string)entry.Key);
191
- string destinationPath = Path.Combine(outputDirectory, (string)entry.Value);
185
+ var sourcePath = Path.Combine(outputDirectory, (string)entry.Key);
186
+ var destinationPath = Path.Combine(outputDirectory, (string)entry.Value);
187
188
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
189
FileSystem.MoveFile(sourcePath, destinationPath);
src/wix/WixToolset.Core.Burn/BurnBackendWarnings.cs
+6
@@ -21,6 +21,11 @@ namespace WixToolset.Core.Burn
21
return Message(sourceLineNumbers, Ids.EmptyContainer, "The Container '{0}' is being ignored because it doesn't have any payloads.", containerId);
22
}
23
24
+ public static Message FailedToExtractAttachedContainers(SourceLineNumber sourceLineNumbers)
25
+ {
26
+ return Message(sourceLineNumbers, Ids.FailedToExtractAttachedContainers, "Failed to extract attached container. This most often happens when extracting a stripped bundle from the package cache, which is not supported.");
27
+ }
28
+
29
private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args)
30
{
31
return new Message(sourceLineNumber, MessageLevel.Warning, (int)id, format, args);
@@ -31,6 +36,7 @@ namespace WixToolset.Core.Burn
36
AttachedContainerPayloadCollision = 8500,
37
AttachedContainerPayloadCollision2 = 8501,
38
EmptyContainer = 8502,
39
+ FailedToExtractAttachedContainers = 8503,
40
} // last available is 8999. 9000 is VerboseMessages.
41
}
42
}
src/wix/WixToolset.Core.Burn/CommandLine/ExtractSubcommand.cs
+9
-1
@@ -52,7 +52,15 @@ namespace WixToolset.Core.Burn.CommandLine
52
using (var reader = BurnReader.Open(this.Messaging, this.InputPath))
53
{
54
reader.ExtractUXContainer(uxExtractPath, this.IntermediateFolder);
55
- reader.ExtractAttachedContainers(this.ExtractPath, this.IntermediateFolder);
55
+
56
+ try
57
+ {
58
+ reader.ExtractAttachedContainers(this.ExtractPath, this.IntermediateFolder);
59
+ }
60
+ catch
61
+ {
62
+ this.Messaging.Write(BurnBackendWarnings.FailedToExtractAttachedContainers(new Data.SourceLineNumber(this.ExtractPath)));
63
+ }
64
}
65
66
return Task.FromResult(this.Messaging.LastErrorNumber);