summaryrefslogtreecommitdiffstats
path: root/core/git-access.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-16 12:55:05 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-19 12:51:01 -0700
commit766f297bc4c01b81ee11ceb724460240403068a1 (patch)
treeb4cac2a274ccb80f2f5da6d80a5792965f88eeae /core/git-access.c
parentfe074ccad153791b32c2f62af530091cb025cdee (diff)
downloadsubsurface-766f297bc4c01b81ee11ceb724460240403068a1.tar.gz
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 <dirk@hohndel.org>
Diffstat (limited to 'core/git-access.c')
-rw-r--r--core/git-access.c11
1 files changed, 11 insertions, 0 deletions
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);
}