diff --git a/azure-pipelines/e2e-assets/asset-caching/failing-script.ps1 b/azure-pipelines/e2e-assets/asset-caching/failing-script.ps1 new file mode 100644 index 0000000000..c232cc056d --- /dev/null +++ b/azure-pipelines/e2e-assets/asset-caching/failing-script.ps1 @@ -0,0 +1 @@ +throw "Script download error" diff --git a/azure-pipelines/end-to-end-tests-dir/asset-caching.ps1 b/azure-pipelines/end-to-end-tests-dir/asset-caching.ps1 index b3725fcb9b..e00df0f361 100644 --- a/azure-pipelines/end-to-end-tests-dir/asset-caching.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/asset-caching.ps1 @@ -197,3 +197,31 @@ $actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$d if (-not ($actual.Contains("Asset cache hit for example3.html; downloaded from: file://$AssetCache"))) { throw "Failure: azurl (yes), x-block-origin (yes), asset-cache (hit), download (n/a)" } + +# Testing x-download failure with asset cache (x-script) and x-block-origin settings +$env:X_VCPKG_ASSET_SOURCES = "clear;x-script,pwsh $PSScriptRoot/../e2e-assets/asset-caching/failing-script.ps1 {url} {sha512} {dst};x-block-origin" +$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--url", "https://example.com", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a")) +# Check for the expected messages in order +$expectedOrder = @( + "error: failed with exit code: (1).", + "error: Missing example3.html and downloads are blocked by x-block-origin." +) + +# Verify order +$index = 0 +foreach ($message in $expectedOrder) { + $index = $actual.IndexOf($message, $index) + if ($index -lt 0) { + throw "Failure: Expected message '$message' not found in the correct order." + } + $index += $message.Length +} + +# Testing x-download success with asset cache (x-script) and x-block-origin settings +Refresh-TestRoot +$env:X_VCPKG_ASSET_SOURCES = "clear;x-script,$TestScriptAssetCacheExe {url} {sha512} {dst};x-block-origin" +$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--url", "https://example.com/hello-world.txt", "--sha512", "09e1e2a84c92b56c8280f4a1203c7cffd61b162cfe987278d4d6be9afbf38c0e8934cdadf83751f4e99d111352bffefc958e5a4852c8a7a29c95742ce59288a8")) +if (-not ($actual.Contains("Successfully downloaded example3.html."))) { + throw "Failure: x-script download success message" +} + diff --git a/src/vcpkg/base/downloads.cpp b/src/vcpkg/base/downloads.cpp index 56e61316c5..c3b2014954 100644 --- a/src/vcpkg/base/downloads.cpp +++ b/src/vcpkg/base/downloads.cpp @@ -974,6 +974,7 @@ namespace vcpkg RedirectedProcessLaunchSettings settings; settings.environment = get_clean_environment(); settings.echo_in_debug = EchoInDebug::Show; + auto maybe_res = flatten(cmd_execute_and_capture_output(cmd, settings), ""); if (maybe_res) { @@ -982,14 +983,14 @@ namespace vcpkg if (maybe_success) { fs.rename(download_path_part_path, download_path, VCPKG_LINE_INFO); + msg::println(msgDownloadSuccesful, msg::path = download_path.filename()); return urls[0]; } - - errors.push_back(std::move(maybe_success).error()); + msg::println_error(maybe_success.error()); } else { - errors.push_back(std::move(maybe_res).error()); + msg::println_error(maybe_res.error()); } } }