Ignore cache bundle failure if it already exists in the package cache.
Fixes 6848
Sean Hall committed
Sep 15, 2022 at 12:17 UTC
a470bbc209dff298dbf86a29393d6a2a8b768dc8
3 files changed
+43
-9
src/burn/engine/cache.cpp
+5
-7
@@ -1000,8 +1000,6 @@ extern "C" HRESULT CacheCompleteBundle(
1000
BOOL fPathEqual = FALSE;
1001
LPWSTR sczTargetDirectory = NULL;
1002
LPWSTR sczTargetPath = NULL;
1003
- LPWSTR sczSourceDirectory = NULL;
1004
- LPWSTR sczPayloadSourcePath = NULL;
1003
1004
hr = CreateCompletedPath(pCache, fPerMachine, wzBundleId, NULL, &sczTargetDirectory);
1005
ExitOnFailure(hr, "Failed to create completed cache path for bundle.");
@@ -1028,18 +1026,18 @@ extern "C" HRESULT CacheCompleteBundle(
1026
FileRemoveFromPendingRename(sczTargetPath); // best effort to ensure bundle is not deleted from cache post restart.
1027
1028
hr = FileEnsureCopyWithRetry(wzSourceBundlePath, sczTargetPath, TRUE, FILE_OPERATION_RETRY_COUNT, FILE_OPERATION_RETRY_WAIT);
1029
+ if (FAILED(hr) && FileExistsEx(sczTargetPath, NULL))
1030
+ {
1031
+ LogId(REPORT_WARNING, MSG_IGNORING_CACHE_BUNDLE_FAILURE, hr);
1032
+ ExitFunction1(hr = S_OK);
1033
+ }
1034
ExitOnFailure(hr, "Failed to cache bundle from: '%ls' to '%ls'", wzSourceBundlePath, sczTargetPath);
1035
1036
// Reset the path permissions in the cache.
1037
hr = ResetPathPermissions(fPerMachine, sczTargetPath);
1038
ExitOnFailure(hr, "Failed to reset permissions on cached bundle: '%ls'", sczTargetPath);
1039
1037
- hr = PathGetDirectory(wzSourceBundlePath, &sczSourceDirectory);
1038
- ExitOnFailure(hr, "Failed to get directory from engine working path: %ls", wzSourceBundlePath);
1039
-
1040
LExit:
1041
- ReleaseStr(sczPayloadSourcePath);
1042
- ReleaseStr(sczSourceDirectory);
1041
ReleaseStr(sczTargetPath);
1042
ReleaseStr(sczTargetDirectory);
1043
src/burn/engine/engine.mc
+7
@@ -862,6 +862,13 @@ Language=English
862
Cached non-vital package: %1!ls!, encountered error: 0x%2!x!. Continuing...
863
.
864
865
+MessageId=345
866
+Severity=Warning
867
+SymbolicName=MSG_IGNORING_CACHE_BUNDLE_FAILURE
868
+Language=English
869
+Ignoring failure to cache bundle because the file already exists, encountered error: 0x%1!x!. Continuing...
870
+.
871
+
872
MessageId=346
873
Severity=Warning
874
SymbolicName=MSG_CACHE_RETRYING_PACKAGE
src/test/burn/WixToolsetTest.BurnE2E/CacheTests.cs
+31
-2
@@ -203,6 +203,35 @@ namespace WixToolsetTest.BurnE2E
203
}
204
}
205
206
+ [RuntimeFact]
207
+ public void CanHandleCachedBundleInPackageCacheInUse()
208
+ {
209
+ var packageA = this.CreatePackageInstaller("PackageA");
210
+ var packageB = this.CreatePackageInstaller("PackageB");
211
+ var bundleA = this.CreateBundleInstaller("BundleA");
212
+
213
+ bundleA.Install();
214
+
215
+ var registration = bundleA.VerifyRegisteredAndInPackageCache();
216
+ var cachedBundlePath = registration.CachePath;
217
+
218
+ packageA.VerifyInstalled(true);
219
+ packageB.VerifyInstalled(true);
220
+
221
+ // Lock the bundle file in the package cache.
222
+ string modifyLogPath;
223
+ using (FileStream lockTargetFile = new FileStream(cachedBundlePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
224
+ {
225
+ modifyLogPath = bundleA.Modify();
226
+ }
227
+
228
+ bundleA.VerifyRegisteredAndInPackageCache();
229
+ packageA.VerifyInstalled(true);
230
+ packageB.VerifyInstalled(true);
231
+
232
+ Assert.True(LogVerifier.MessageInLogFile(modifyLogPath, "w345: Ignoring failure to cache bundle because the file already exists, encountered error: 0x80070020. Continuing..."));
233
+ }
234
+
235
[RuntimeFact]
236
public void CanGetEngineWorkingDirectoryFromCommandLine()
237
{
@@ -215,7 +244,7 @@ namespace WixToolsetTest.BurnE2E
244
{
245
var baseTempPath = dfs.GetFolder(true);
246
var logPath = bundleA.Install(0, $"-burn.engine.working.directory=\"{baseTempPath}\"");
218
- LogVerifier.MessageInLogFileRegex(logPath, $"Burn x86 v4.*, Windows v.* \\(Build .*: Service Pack .*\\), path: {baseTempPath.Replace("\\", "\\\\")}\\\\.*\\\\.cr\\\\BundleA.exe");
247
+ Assert.True(LogVerifier.MessageInLogFileRegex(logPath, $"Burn x86 v4.*, Windows v.* \\(Build .*: Service Pack .*\\), path: {baseTempPath.Replace("\\", "\\\\")}\\\\.*\\\\.cr\\\\BundleA.exe"));
248
}
249
}
250
@@ -251,7 +280,7 @@ namespace WixToolsetTest.BurnE2E
280
}
281
282
var logPath = bundleA.Install();
254
- LogVerifier.MessageInLogFileRegex(logPath, $"Burn x86 v4.*, Windows v.* \\(Build .*: Service Pack .*\\), path: {baseTempPath.Replace("\\", "\\\\")}\\\\.*\\\\.cr\\\\BundleA.exe");
283
+ Assert.True(LogVerifier.MessageInLogFileRegex(logPath, $"Burn x86 v4.*, Windows v.* \\(Build .*: Service Pack .*\\), path: {baseTempPath.Replace("\\", "\\\\")}\\\\.*\\\\.cr\\\\BundleA.exe"));
284
}
285
}
286
finally