Skip to content

Commit

Permalink
scalar: only try GVFS protocol on https:// URLs
Browse files Browse the repository at this point in the history
Well, technically also the http:// protocol is allowed _when testing_...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Nov 8, 2023
1 parent 900a3a4 commit 05931bd
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ static int get_cache_server_url(struct json_iterator *it)
return 0;
}

static int can_url_support_gvfs(const char *url)
{
return starts_with(url, "https://") ||
(git_env_bool("GIT_TEST_ALLOW_GVFS_VIA_HTTP", 0) &&
starts_with(url, "http://"));
}

/*
* If `cache_server_url` is `NULL`, print the list to `stdout`.
*
Expand All @@ -403,6 +410,13 @@ static int supports_gvfs_protocol(const char *url, char **cache_server_url)
struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf out = STRBUF_INIT;

/*
* The GVFS protocol is only supported via https://; For testing, we
* also allow http://.
*/
if (!can_url_support_gvfs(url))
return 0;

cp.git_cmd = 1;
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url, "config", NULL);
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
Expand Down Expand Up @@ -471,19 +485,26 @@ static char *get_cache_key(const char *url)
struct strbuf out = STRBUF_INIT;
char *cache_key = NULL;

cp.git_cmd = 1;
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
"endpoint", "vsts/info", NULL);
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
char *id = NULL;
struct json_iterator it =
JSON_ITERATOR_INIT(out.buf, get_repository_id, &id);

if (iterate_json(&it) < 0)
warning("JSON parse error (%s)", out.buf);
else if (id)
cache_key = xstrfmt("id_%s", id);
free(id);
/*
* The GVFS protocol is only supported via https://; For testing, we
* also allow http://.
*/
if (can_url_support_gvfs(url)) {
cp.git_cmd = 1;
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
"endpoint", "vsts/info", NULL);
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
char *id = NULL;
struct json_iterator it =
JSON_ITERATOR_INIT(out.buf, get_repository_id,
&id);

if (iterate_json(&it) < 0)
warning("JSON parse error (%s)", out.buf);
else if (id)
cache_key = xstrfmt("id_%s", id);
free(id);
}
}

if (!cache_key) {
Expand Down

0 comments on commit 05931bd

Please sign in to comment.