Skip to content

Commit 5d96408

Browse files
authored
Fix command line too long when sending to GitHub dependency graph (#1144)
1 parent 9a4e2ef commit 5d96408

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

include/vcpkg/base/downloads.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace vcpkg
3636
View<std::pair<std::string, Path>> url_pairs,
3737
View<std::string> headers);
3838

39-
bool send_snapshot_to_api(const std::string& github_token,
39+
bool send_snapshot_to_api(const Filesystem& fs,
40+
const std::string& github_token,
4041
const std::string& github_repository,
4142
const Json::Object& snapshot);
4243
ExpectedL<int> put_file(const ReadOnlyFilesystem&,

src/vcpkg/base/downloads.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <vcpkg/base/system.process.h>
1313
#include <vcpkg/base/system.proxy.h>
1414
#include <vcpkg/base/util.h>
15+
#include <vcpkg/base/uuid.h>
1516

1617
#include <vcpkg/commands.version.h>
1718
#include <vcpkg/metrics.h>
@@ -521,7 +522,8 @@ namespace vcpkg
521522
return ret;
522523
}
523524

524-
bool send_snapshot_to_api(const std::string& github_token,
525+
bool send_snapshot_to_api(const Filesystem& fs,
526+
const std::string& github_token,
525527
const std::string& github_repository,
526528
const Json::Object& snapshot)
527529
{
@@ -538,7 +540,13 @@ namespace vcpkg
538540
cmd.string_arg("-H").string_arg("X-GitHub-Api-Version: 2022-11-28");
539541
cmd.string_arg(
540542
Strings::concat("https://api.github.com/repos/", github_repository, "/dependency-graph/snapshots"));
541-
cmd.string_arg("-d").string_arg(Json::stringify(snapshot));
543+
544+
const auto tmp_dir = fs.create_or_get_temp_directory(VCPKG_LINE_INFO);
545+
const auto unique_file_name = fmt::format("dependency_snapshot_{}.json", generate_random_UUID());
546+
const auto snapshot_file_path = tmp_dir / unique_file_name;
547+
fs.write_contents(snapshot_file_path, Json::stringify(snapshot), VCPKG_LINE_INFO);
548+
549+
cmd.string_arg("-d").string_arg(fmt::format("@{}", snapshot_file_path));
542550
int code = 0;
543551
auto result = cmd_execute_and_stream_lines(cmd, [&code](StringView line) {
544552
if (Strings::starts_with(line, guid_marker))

src/vcpkg/commands.set-installed.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ namespace vcpkg::Commands::SetInstalled
193193
bool s = false;
194194
if (snapshot.has_value() && args.github_token.has_value() && args.github_repository.has_value())
195195
{
196-
s = send_snapshot_to_api(*args.github_token.get(), *args.github_repository.get(), *snapshot.get());
196+
s = send_snapshot_to_api(fs, *args.github_token.get(), *args.github_repository.get(), *snapshot.get());
197197
if (s)
198198
{
199199
msg::println(msgDependencyGraphSuccess);

0 commit comments

Comments
 (0)