From 766f297bc4c01b81ee11ceb724460240403068a1 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 16 Apr 2021 12:55:05 -0700 Subject: cloudstorage: try alternative server if first connection fails If we can't reach our preferred server, try using a different one. The diff makes more sense when ignoring white space. With this we check the connection to the cloud server much earlier and in case of failure to connect try a different cloud_base_url. Signed-off-by: Dirk Hohndel --- core/git-access.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'core/git-access.c') diff --git a/core/git-access.c b/core/git-access.c index 31ab9f1d8..c66a24a5d 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -716,6 +716,8 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc return 0; } + // we know that we already checked for the cloud server, but to give a decent warning message + // here in case none of them are reachable, let's check one more time if (is_subsurface_cloud && !canReachCloudServer()) { // this is not an error, just a warning message, so return 0 SSRF_INFO("git storage: cannot connect to remote server"); @@ -723,6 +725,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc git_storage_update_progress(translate("gettextFromC", "Can't reach cloud server, working with local data")); return 0; } + if (verbose) SSRF_INFO("git storage: fetch remote %s\n", git_remote_url(origin)); git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; @@ -1042,6 +1045,14 @@ static struct git_repository *is_remote_git_repository(char *remote, const char * this is used to create more user friendly error message and warnings */ is_subsurface_cloud = strstr(remote, prefs.cloud_base_url) != NULL; + /* if we are planning to access the server, make sure it's available and try to + * pick one of the alternative servers if necessary */ + if (is_subsurface_cloud && !git_local_only) { + // since we know that this is Subsurface cloud storage, we don't have to + // worry about the local directory name changing if we end up with a different + // cloud_base_url... the algorithm normalizes those URLs + (void)canReachCloudServer(); + } return get_remote_repo(localdir, remote, branch); } -- cgit v1.2.3-70-g09d2