@@ -527,8 +527,7 @@ namespace vcpkg
527527 StringView url,
528528 const std::vector<std::string>& secrets,
529529 View<std::string> headers,
530- const Path& file,
531- StringView method)
530+ const Path& file)
532531 {
533532 static constexpr StringLiteral guid_marker = " 9a1db05f-a65d-419b-aa72-037fb4d0672e" ;
534533
@@ -555,7 +554,7 @@ namespace vcpkg
555554 return std::move (maybe_res).error ();
556555 }
557556
558- auto http_cmd = Command{" curl" }.string_arg (" -X" ).string_arg (method );
557+ auto http_cmd = Command{" curl" }.string_arg (" -X" ).string_arg (" PUT " );
559558 for (auto && header : headers)
560559 {
561560 http_cmd.string_arg (" -H" ).string_arg (header);
@@ -586,6 +585,61 @@ namespace vcpkg
586585 return 0 ;
587586 }
588587
588+ ExpectedL<Unit> patch_file (const Filesystem& fs,
589+ StringView url,
590+ View<std::string> headers,
591+ const Path& file,
592+ std::size_t file_size,
593+ std::size_t chunk_size)
594+ {
595+ static constexpr StringLiteral guid_marker = " 9a1db05f-a65d-419b-aa72-037fb4d0672e" ;
596+
597+ Command base_cmd;
598+ base_cmd.string_arg (" curl" ).string_arg (" -X" ).string_arg (" PATCH" ).string_arg (" -w" ).string_arg (
599+ " \\ n" + guid_marker.to_string () + " %{http_code}\n " );
600+ for (auto && header : headers)
601+ {
602+ base_cmd.string_arg (" -H" ).string_arg (header);
603+ }
604+ base_cmd.string_arg (url);
605+
606+ auto file_ptr = fs.open_for_read (file, VCPKG_LINE_INFO);
607+ std::vector<char > buffer (chunk_size);
608+ std::size_t bytes_read = 0 ;
609+ for (std::size_t i = 0 ; i < file_size; i += bytes_read)
610+ {
611+ bytes_read = file_ptr.read (buffer.data (), sizeof (decltype (buffer)::value_type), chunk_size);
612+ if (!bytes_read)
613+ {
614+ return msg::format_error (
615+ msgFileReadFailed, msg::path = file, msg::byte_offset = i, msg::count = chunk_size);
616+ }
617+
618+ auto cmd = base_cmd;
619+ cmd.string_arg (" -H" )
620+ .string_arg (fmt::format (" Content-Range: bytes {}-{}/{}" , i, i + bytes_read - 1 , file_size))
621+ .string_arg (" --data-binary" )
622+ .string_arg (" @-" );
623+
624+ int code = 0 ;
625+ RedirectedProcessLaunchSettings launch_settings;
626+ launch_settings.stdin_content = {buffer.data (), bytes_read};
627+ auto res = cmd_execute_and_stream_lines (cmd, launch_settings, [&code](StringView line) {
628+ if (Strings::starts_with (line, guid_marker))
629+ {
630+ code = std::strtol (line.data () + guid_marker.size (), nullptr , 10 );
631+ }
632+ });
633+ if (!res.get () || *res.get () != 0 || (code >= 100 && code < 200 ) || code >= 300 )
634+ {
635+ return msg::format_error (
636+ msgCurlFailedToPutHttp, msg::exit_code = res.value_or (-1 ), msg::url = url, msg::value = code);
637+ }
638+ }
639+
640+ return Unit{};
641+ }
642+
589643 std::string format_url_query (StringView base_url, View<std::string> query_params)
590644 {
591645 auto url = base_url.to_string ();
0 commit comments