diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 3559fd4275..4385266eac 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -961,7 +962,11 @@ namespace virtual LocalizedString restored_message(size_t count, std::chrono::high_resolution_clock::duration elapsed) const = 0; + /// checks if package abi is present in this storage + /// NOTE: Operation must be thread safe. Multiple calls will occur in parallel virtual ExpectedL stat(StringView url) const = 0; + /// download a package zip from this storage + /// NOTE: Operation must be thread safe. Multiple calls will occur in parallel virtual ExpectedL download_file(StringView object, const Path& archive) const = 0; virtual ExpectedL upload_file(StringView object, const Path& archive) const = 0; }; @@ -988,38 +993,36 @@ namespace void acquire_zips(View actions, Span> out_zip_paths) const override { - for (size_t idx = 0; idx < actions.size(); ++idx) - { - auto&& action = *actions[idx]; - const auto& abi = action.package_abi().value_or_exit(VCPKG_LINE_INFO); - auto tmp = make_temp_archive_path(m_buildtrees, action.spec); - auto res = m_tool->download_file(make_object_path(m_prefix, abi), tmp); - if (res) - { - out_zip_paths[idx].emplace(std::move(tmp), RemoveWhen::always); - } - else - { - out_sink.println_warning(res.error()); - } - } + parallel_transform( + actions, out_zip_paths.begin(), [&](const InstallPlanAction* plan) -> Optional { + const auto& abi = plan->package_abi().value_or_exit(VCPKG_LINE_INFO); + auto tmp = make_temp_archive_path(m_buildtrees, plan->spec); + auto res = m_tool->download_file(make_object_path(m_prefix, abi), tmp); + if (res) + { + return ZipResource{ZipResource(std::move(tmp), RemoveWhen::always)}; + } + else + { + out_sink.println_warning(res.error()); + return nullopt; + } + }); } void precheck(View actions, Span cache_status) const override { - for (size_t idx = 0; idx < actions.size(); ++idx) - { - auto&& action = *actions[idx]; - const auto& abi = action.package_abi().value_or_exit(VCPKG_LINE_INFO); + parallel_transform(actions, cache_status.begin(), [&](const InstallPlanAction* plan) { + const auto& abi = plan->package_abi().value_or_exit(VCPKG_LINE_INFO); if (m_tool->stat(make_object_path(m_prefix, abi))) { - cache_status[idx] = CacheAvailability::available; + return CacheAvailability::available; } else { - cache_status[idx] = CacheAvailability::unavailable; + return CacheAvailability::unavailable; } - } + }); } LocalizedString restored_message(size_t count,