diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index afccc8d89a..bb26e1f209 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1128,7 +1128,21 @@ namespace cmd.string_arg("--no-sign-request"); } - return flatten(cmd_execute_and_capture_output(cmd), Tools::AWSCLI).map(unit_to_cache_hit); + auto maybe_exit = cmd_execute_and_capture_output(cmd); + // When the file is not found, "aws s3 ls" prints nothing, and returns exit code 1. + // flatten() would treat this as an error, but we want to treat it as a (silent) cache miss instead. + // See https://github.com/aws/aws-cli/issues/5544 for the related aws-cli bug report. + if (auto exit = maybe_exit.get()) + { + // We want to return CacheResult::miss even if aws-cli starts to return success + const bool success_or_exit_code_1 = exit->exit_code == 0 || exit->exit_code == 1; + const bool output_is_empty = Strings::trim(exit->output) == ""; + if (success_or_exit_code_1 && output_is_empty) + { + return CacheResult::miss; + } + } + return flatten(maybe_exit, Tools::AWSCLI).map(unit_to_cache_hit); } ExpectedL download_file(StringView object, const Path& archive) const override