summaryrefslogtreecommitdiffstats
path: root/core/checkcloudconnection.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-18 16:28:25 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-19 12:51:01 -0700
commit9620d1182885bb8ac0dd05eeaf8d4e108461cfab (patch)
tree7a019ad76434becd161e07258ce30eaeb870a0d6 /core/checkcloudconnection.cpp
parent766f297bc4c01b81ee11ceb724460240403068a1 (diff)
downloadsubsurface-9620d1182885bb8ac0dd05eeaf8d4e108461cfab.tar.gz
cloudstorage: update remote if cloud server changes
If we can't reach the cloud server in the URL (which might come from the settings or be passed in by the user), we try the alternative server(s). If we end up changing servers, we need to update the remote that we have already parsed from the URL. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/checkcloudconnection.cpp')
-rw-r--r--core/checkcloudconnection.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/core/checkcloudconnection.cpp b/core/checkcloudconnection.cpp
index 05e529b90..b8e9fc26f 100644
--- a/core/checkcloudconnection.cpp
+++ b/core/checkcloudconnection.cpp
@@ -11,6 +11,7 @@
#include "git-access.h"
#include "errorhelper.h"
#include "core/subsurface-string.h"
+#include "core/membuffer.h"
#include "core/settings/qPrefCloudStorage.h"
#include "checkcloudconnection.h"
@@ -197,9 +198,20 @@ void CheckCloudConnection::gotContinent(QNetworkReply *reply)
}
// helper to be used from C code
-extern "C" bool canReachCloudServer()
+extern "C" bool canReachCloudServer(const char **remote)
{
if (verbose)
- qWarning() << "Cloud storage: checking connection to cloud server";
- return CheckCloudConnection().checkServer();
+ qWarning() << "Cloud storage: checking connection to cloud server" << *remote;
+ bool connection = CheckCloudConnection().checkServer();
+ if (strstr(*remote, prefs.cloud_base_url) == nullptr) {
+ // we switched the cloud URL - likely because we couldn't reach the server passed in
+ // the strstr with the offset is designed so we match the right component in the name;
+ // the cloud_base_url ends with a '/', so we need the text starting at "git/..."
+ char *newremote = format_string("%s%s", prefs.cloud_base_url, strstr(*remote, "org/git/") + 4);
+ if (verbose)
+ qDebug() << "updating remote to: " << newremote;
+ free((void*)*remote);
+ *remote = newremote;
+ }
+ return connection;
}