Layout using the source engine handle
Rob Mensching committed
Apr 12, 2021 at 23:52 UTC
70adfc49cb05da4e7b9eb50a0c47635d2d20b366
7 files changed
+49
-17
src/engine/apply.cpp
+38
-6
@@ -69,6 +69,7 @@ static void UpdateCacheSuccessProgress(
69
__inout DWORD64* pqwSuccessfulCachedProgress
70
);
71
static HRESULT LayoutBundle(
72
+ __in HANDLE hSourceEngineFile,
73
__in BURN_USER_EXPERIENCE* pUX,
74
__in BURN_VARIABLES* pVariables,
75
__in HANDLE hPipe,
@@ -114,6 +115,7 @@ static HRESULT PromptForSource(
115
);
116
static HRESULT CopyPayload(
117
__in BURN_CACHE_ACQUIRE_PROGRESS_CONTEXT* pProgress,
118
+ __in HANDLE hSourceFile,
119
__in_z LPCWSTR wzSourcePath,
120
__in_z LPCWSTR wzDestinationPath
121
);
@@ -510,7 +512,7 @@ extern "C" HRESULT ApplyCache(
512
break;
513
514
case BURN_CACHE_ACTION_TYPE_LAYOUT_BUNDLE:
513
- hr = LayoutBundle(pUX, pVariables, hPipe, pCacheAction->bundleLayout.sczExecutableName, pCacheAction->bundleLayout.sczLayoutDirectory, pCacheAction->bundleLayout.sczUnverifiedPath, qwSuccessfulCachedProgress, pPlan->qwCacheSizeTotal);
515
+ hr = LayoutBundle(hSourceEngineFile, pUX, pVariables, hPipe, pCacheAction->bundleLayout.sczExecutableName, pCacheAction->bundleLayout.sczLayoutDirectory, pCacheAction->bundleLayout.sczUnverifiedPath, qwSuccessfulCachedProgress, pPlan->qwCacheSizeTotal);
516
if (SUCCEEDED(hr))
517
{
518
UpdateCacheSuccessProgress(pPlan, pCacheAction, &qwSuccessfulCachedProgress);
@@ -1053,6 +1055,7 @@ static void UpdateCacheSuccessProgress(
1055
}
1056
1057
static HRESULT LayoutBundle(
1058
+ __in HANDLE hSourceEngineFile,
1059
__in BURN_USER_EXPERIENCE* pUX,
1060
__in BURN_VARIABLES* pVariables,
1061
__in HANDLE hPipe,
@@ -1090,7 +1093,7 @@ static HRESULT LayoutBundle(
1093
hr = PathCompare(sczBundlePath, sczDestinationPath, &nEquivalentPaths);
1094
ExitOnFailure(hr, "Failed to determine if layout bundle path was equivalent with current process path.");
1095
1093
- if (CSTR_EQUAL == nEquivalentPaths)
1096
+ if (CSTR_EQUAL == nEquivalentPaths && FileExistsEx(sczDestinationPath, NULL))
1097
{
1098
ExitFunction1(hr = S_OK);
1099
}
@@ -1112,7 +1115,7 @@ static HRESULT LayoutBundle(
1115
hr = UserExperienceOnCacheAcquireBegin(pUX, NULL, NULL, BOOTSTRAPPER_CACHE_OPERATION_COPY, sczBundlePath);
1116
ExitOnRootFailure(hr, "BA aborted cache acquire begin.");
1117
1115
- hr = CopyPayload(&progress, sczBundlePath, wzUnverifiedPath);
1118
+ hr = CopyPayload(&progress, hSourceEngineFile, sczBundlePath, wzUnverifiedPath);
1119
// Error handling happens after sending complete message to BA.
1120
1121
UserExperienceOnCacheAcquireComplete(pUX, NULL, NULL, hr, &fRetryAcquire);
@@ -1239,7 +1242,7 @@ static HRESULT AcquireContainerOrPayload(
1242
hr = UserExperienceOnCacheAcquireBegin(pUX, wzPackageOrContainerId, wzPayloadId, BOOTSTRAPPER_CACHE_OPERATION_COPY, sczSourceFullPath);
1243
ExitOnRootFailure(hr, "BA aborted cache acquire begin.");
1244
1242
- hr = CopyPayload(&progress, sczSourceFullPath, wzDestinationPath);
1245
+ hr = CopyPayload(&progress, INVALID_HANDLE_VALUE, sczSourceFullPath, wzDestinationPath);
1246
// Error handling happens after sending complete message to BA.
1247
1248
// We successfully copied from a source location, set that as the last used source.
@@ -1432,6 +1435,7 @@ LExit:
1435
1436
static HRESULT CopyPayload(
1437
__in BURN_CACHE_ACQUIRE_PROGRESS_CONTEXT* pProgress,
1438
+ __in HANDLE hSourceFile,
1439
__in_z LPCWSTR wzSourcePath,
1440
__in_z LPCWSTR wzDestinationPath
1441
)
@@ -1440,6 +1444,8 @@ static HRESULT CopyPayload(
1444
DWORD dwFileAttributes = 0;
1445
LPCWSTR wzPackageOrContainerId = pProgress->pContainer ? pProgress->pContainer->sczId : pProgress->pPackage ? pProgress->pPackage->sczId : L"";
1446
LPCWSTR wzPayloadId = pProgress->pPayload ? pProgress->pPayload->sczKey : L"";
1447
+ HANDLE hDestinationFile = INVALID_HANDLE_VALUE;
1448
+ HANDLE hSourceOpenedFile = INVALID_HANDLE_VALUE;
1449
1450
DWORD dwLogId = pProgress->pContainer ? (pProgress->pPayload ? MSG_ACQUIRE_CONTAINER_PAYLOAD : MSG_ACQUIRE_CONTAINER) : pProgress->pPackage ? MSG_ACQUIRE_PACKAGE_PAYLOAD : MSG_ACQUIRE_BUNDLE_PAYLOAD;
1451
LogId(REPORT_STANDARD, dwLogId, wzPackageOrContainerId, wzPayloadId, "copy", wzSourcePath);
@@ -1457,7 +1463,30 @@ static HRESULT CopyPayload(
1463
}
1464
}
1465
1460
- if (!::CopyFileExW(wzSourcePath, wzDestinationPath, CacheProgressRoutine, pProgress, &pProgress->fCancel, 0))
1466
+ if (INVALID_HANDLE_VALUE == hSourceFile)
1467
+ {
1468
+ hSourceOpenedFile = ::CreateFileW(wzSourcePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
1469
+ if (INVALID_HANDLE_VALUE == hSourceOpenedFile)
1470
+ {
1471
+ ExitWithLastError(hr, "Failed to open source file to copy payload from: '%ls' to: %ls.", wzSourcePath, wzDestinationPath);
1472
+ }
1473
+
1474
+ hSourceFile = hSourceOpenedFile;
1475
+ }
1476
+ else
1477
+ {
1478
+ hr = FileSetPointer(hSourceFile, 0, NULL, FILE_BEGIN);
1479
+ ExitOnRootFailure(hr, "Failed to read from start of source file to copy payload from: '%ls' to: %ls.", wzSourcePath, wzDestinationPath);
1480
+ }
1481
+
1482
+ hDestinationFile = ::CreateFileW(wzDestinationPath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
1483
+ if (INVALID_HANDLE_VALUE == hDestinationFile)
1484
+ {
1485
+ ExitWithLastError(hr, "Failed to open destination file to copy payload from: '%ls' to: %ls.", wzSourcePath, wzDestinationPath);
1486
+ }
1487
+
1488
+ hr = FileCopyUsingHandlesWithProgress(hSourceFile, hDestinationFile, 0, CacheProgressRoutine, pProgress);
1489
+ if (FAILED(hr))
1490
{
1491
if (pProgress->fCancel)
1492
{
@@ -1466,11 +1495,14 @@ static HRESULT CopyPayload(
1495
}
1496
else
1497
{
1469
- ExitWithLastError(hr, "Failed attempt to copy payload from: '%ls' to: %ls.", wzSourcePath, wzDestinationPath);
1498
+ ExitOnRootFailure(hr, "Failed attempt to copy payload from: '%ls' to: %ls.", wzSourcePath, wzDestinationPath);
1499
}
1500
}
1501
1502
LExit:
1503
+ ReleaseFileHandle(hDestinationFile);
1504
+ ReleaseFileHandle(hSourceOpenedFile);
1505
+
1506
return hr;
1507
}
1508
src/engine/engine.vcxproj
+2
-2
@@ -1,7 +1,7 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4
- <Import Project="..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props')" />
4
+ <Import Project="..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props')" />
5
<ItemGroup Label="ProjectConfigurations">
6
<ProjectConfiguration Include="Debug|Win32">
7
<Configuration>Debug</Configuration>
@@ -165,7 +165,7 @@ rc.exe -fo "$(OutDir)engine.res" "$(IntDir)engine.messages.rc"</Command>
165
<PropertyGroup>
166
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
167
</PropertyGroup>
168
- <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props'))" />
168
<Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets'))" />
169
+ <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props'))" />
170
</Target>
171
</Project>
\ No newline at end of file
src/engine/packages.config
+1
-1
@@ -1,5 +1,5 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<packages>
3
<package id="Nerdbank.GitVersioning" version="3.3.37" targetFramework="native" developmentDependency="true" />
4
- <package id="WixToolset.DUtil" version="4.0.67" targetFramework="native" />
4
+ <package id="WixToolset.DUtil" version="4.0.70" targetFramework="native" />
5
</packages>
\ No newline at end of file
src/stub/packages.config
+1
-1
@@ -4,5 +4,5 @@
4
<package id="Microsoft.SourceLink.Common" version="1.0.0" targetFramework="native" developmentDependency="true" />
5
<package id="Microsoft.SourceLink.GitHub" version="1.0.0" targetFramework="native" developmentDependency="true" />
6
<package id="Nerdbank.GitVersioning" version="3.3.37" targetFramework="native" developmentDependency="true" />
7
- <package id="WixToolset.DUtil" version="4.0.67" targetFramework="native" />
7
+ <package id="WixToolset.DUtil" version="4.0.70" targetFramework="native" />
8
</packages>
\ No newline at end of file
src/stub/stub.vcxproj
+2
-2
@@ -2,10 +2,10 @@
2
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
4
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5
+ <Import Project="..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props')" />
6
<Import Project="..\..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props" Condition="Exists('..\..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props')" />
7
<Import Project="..\..\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.props" Condition="Exists('..\..\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.props')" />
8
<Import Project="..\..\packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.props" Condition="Exists('..\..\packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.props')" />
8
- <Import Project="..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props')" />
9
10
<ItemGroup Label="ProjectConfigurations">
11
<ProjectConfiguration Include="Debug|Win32">
@@ -117,6 +117,6 @@
117
<Error Condition="!Exists('..\..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.props'))" />
118
<Error Condition="!Exists('..\..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets'))" />
119
<Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.3.3.37\build\Nerdbank.GitVersioning.targets'))" />
120
- <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props'))" />
120
+ <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props'))" />
121
</Target>
122
</Project>
\ No newline at end of file
src/test/BurnUnitTest/BurnUnitTest.vcxproj
+2
-2
@@ -3,8 +3,8 @@
3
4
5
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6
+ <Import Project="..\..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props" Condition="Exists('..\..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props')" />
7
<Import Project="..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\build\WixBuildTools.TestSupport.Native.props" Condition="Exists('..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\build\WixBuildTools.TestSupport.Native.props')" />
7
- <Import Project="..\..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props" Condition="Exists('..\..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props')" />
8
<ItemGroup Label="ProjectConfigurations">
9
<ProjectConfiguration Include="Debug|ARM64">
10
<Configuration>Debug</Configuration>
@@ -97,6 +97,6 @@
97
</PropertyGroup>
98
<Error Condition="!Exists('..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\build\WixBuildTools.TestSupport.Native.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\build\WixBuildTools.TestSupport.Native.props'))" />
99
<Error Condition="!Exists('..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\build\WixBuildTools.TestSupport.Native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixBuildTools.TestSupport.Native.4.0.47\build\WixBuildTools.TestSupport.Native.targets'))" />
100
- <Error Condition="!Exists('..\..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixToolset.DUtil.4.0.67\build\WixToolset.DUtil.props'))" />
100
+ <Error Condition="!Exists('..\..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\WixToolset.DUtil.4.0.70\build\WixToolset.DUtil.props'))" />
101
</Target>
102
</Project>
\ No newline at end of file
src/test/BurnUnitTest/packages.config
+3
-3
@@ -1,6 +1,9 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
<packages>
4
+ <package id="WixBuildTools.TestSupport" version="4.0.47" />
5
+ <package id="WixBuildTools.TestSupport.Native" version="4.0.47" />
6
+ <package id="WixToolset.DUtil" version="4.0.70" targetFramework="native" />
7
<package id="xunit.abstractions" version="2.0.3" />
8
<package id="xunit.assert" version="2.4.1" />
9
<package id="xunit.core" version="2.4.1" />
@@ -8,7 +11,4 @@
11
<package id="xunit.extensibility.execution" version="2.4.1" />
12
<package id="xunit.runner.msbuild" version="2.4.1" />
13
<package id="xunit.runner.visualstudio" version="2.4.1" />
11
- <package id="WixBuildTools.TestSupport" version="4.0.47" />
12
- <package id="WixBuildTools.TestSupport.Native" version="4.0.47" />
13
- <package id="WixToolset.DUtil" version="4.0.67" targetFramework="native" />
14
</packages>
\ No newline at end of file