Add support for downloading embedded payloads.
#5253
Sean Hall committed
Apr 25, 2021 at 21:52 UTC
bf31c11edf14789d22ce6542549a807d5c5ff086
4 files changed
+21
-22
src/engine/apply.cpp
+19
-10
@@ -1422,19 +1422,19 @@ static HRESULT AcquireContainerOrPayload(
1422
hr = CacheGetLocalSourcePaths(wzRelativePath, *pwzSourcePath, wzDestinationPath, pContext->wzLayoutDirectory, pContext->pVariables, &pContext->rgSearchPaths, &pContext->cSearchPaths, &dwChosenSearchPath, &dwDestinationSearchPath);
1423
ExitOnFailure(hr, "Failed to search local source.");
1424
1425
- // When a payload comes from a container, the container has the highest chance of being correct.
1426
- // But we want to avoid extracting the container multiple times.
1427
- // So only consider the destination path, which means the container was already extracted.
1425
if (wzPayloadContainerId)
1426
{
1427
+ // When a payload comes from a container, the container has the highest chance of being correct.
1428
+ // But we want to avoid extracting the container multiple times.
1429
+ // So only consider the destination path, which means the container was already extracted.
1430
if (FileExistsEx(pContext->rgSearchPaths[dwDestinationSearchPath], NULL))
1431
{
1432
fFoundLocal = TRUE;
1433
dwChosenSearchPath = dwDestinationSearchPath;
1434
}
1435
- else
1435
+ else // don't prefer the container if extracting it already failed.
1436
{
1437
- fPreferExtract = TRUE;
1437
+ fPreferExtract = SUCCEEDED(pPayload->pContainer->hrExtract);
1438
}
1439
}
1440
@@ -1470,14 +1470,14 @@ static HRESULT AcquireContainerOrPayload(
1470
{
1471
resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_LOCAL;
1472
}
1473
- else if (wzPayloadContainerId)
1474
- {
1475
- resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_CONTAINER;
1476
- }
1473
else if (*pwzDownloadUrl && **pwzDownloadUrl)
1474
{
1475
resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_DOWNLOAD;
1476
}
1477
+ else if (wzPayloadContainerId)
1478
+ {
1479
+ resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_CONTAINER;
1480
+ }
1481
}
1482
1483
// Let the BA have a chance to override the source.
@@ -1526,7 +1526,7 @@ static HRESULT AcquireContainerOrPayload(
1526
1527
break;
1528
case BOOTSTRAPPER_CACHE_OPERATION_EXTRACT:
1529
- Assert(pPayload->pContainer);
1529
+ Assert(pPayload && pPayload->pContainer);
1530
1531
hr = ApplyExtractContainer(pContext, pPayload->pContainer);
1532
ExitOnFailure(hr, "Failed to extract container for payload: %ls", wzPayloadId);
@@ -1541,6 +1541,15 @@ static HRESULT AcquireContainerOrPayload(
1541
hr = CompleteCacheProgress(pProgress, pContainer ? pContainer->qwFileSize : pPayload->qwFileSize);
1542
1543
LExit:
1544
+ if (BOOTSTRAPPER_CACHE_OPERATION_EXTRACT == cacheOperation)
1545
+ {
1546
+ if (FAILED(hr) && SUCCEEDED(pPayload->pContainer->hrExtract) &&
1547
+ (fFoundLocal || pPayload->downloadSource.sczUrl && *pPayload->downloadSource.sczUrl))
1548
+ {
1549
+ *pfRetry = TRUE;
1550
+ }
1551
+ pPayload->pContainer->hrExtract = hr;
1552
+ }
1553
UserExperienceOnCacheAcquireComplete(pContext->pUX, wzPackageOrContainerId, wzPayloadId, hr, pfRetry);
1554
1555
pContext->cSearchPathsMax = max(pContext->cSearchPaths, pContext->cSearchPathsMax);
src/engine/container.h
+1
@@ -79,6 +79,7 @@ typedef struct _BURN_CONTAINER
79
DWORD64 qwExtractSizeTotal;
80
DWORD64 qwCommittedCacheProgress;
81
DWORD64 qwCommittedExtractProgress;
82
+ HRESULT hrExtract;
83
} BURN_CONTAINER;
84
85
typedef struct _BURN_CONTAINERS
src/engine/externalengine.cpp
-12
@@ -357,12 +357,6 @@ HRESULT ExternalEngineSetLocalSource(
357
hr = PayloadFindById(&pEngineState->payloads, wzPayloadId, &pPayload);
358
ExitOnFailure(hr, "BA requested unknown payload with id: %ls", wzPayloadId);
359
360
- if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging)
361
- {
362
- hr = HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION);
363
- ExitOnFailure(hr, "BA denied while trying to set source on embedded payload: %ls", wzPayloadId);
364
- }
365
-
360
hr = StrAllocString(&pPayload->sczSourcePath, wzPath, 0);
361
ExitOnFailure(hr, "Failed to set source path for payload.");
362
}
@@ -408,12 +402,6 @@ HRESULT ExternalEngineSetDownloadSource(
402
hr = PayloadFindById(&pEngineState->payloads, wzPayloadId, &pPayload);
403
ExitOnFailure(hr, "BA requested unknown payload with id: %ls", wzPayloadId);
404
411
- if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging)
412
- {
413
- hr = HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION);
414
- ExitOnFailure(hr, "BA denied while trying to set download URL on embedded payload: %ls", wzPayloadId);
415
- }
416
-
405
pDownloadSource = &pPayload->downloadSource;
406
}
407
else if (wzPackageOrContainerId && *wzPackageOrContainerId)
src/engine/plan.cpp
+1
@@ -1832,6 +1832,7 @@ static void ResetPlannedContainerState(
1832
pContainer->qwExtractSizeTotal = 0;
1833
pContainer->qwCommittedCacheProgress = 0;
1834
pContainer->qwCommittedExtractProgress = 0;
1835
+ pContainer->hrExtract = S_OK;
1836
}
1837
1838
static void ResetPlannedPayloadsState(