cloudstorage: create consistent local directory names

With the new names for the cloud server we'd get different local cache
directory names depending on which server gets used. In order to avoid
that, normalize the name before generating the hash that determines the
local directory name.

Additionally, the old code had an extra '/' in the URL, due to the way
the URL was assembled. Again, to match the existing hash for people
upgrading from older Subsurface versions, add that to our normalized
name as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2021-04-11 15:26:06 -07:00
parent 7fa031b648
commit cfe20ee5f4
3 changed files with 24 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include "trip.h"
#include "imagedownloader.h"
#include "xmlparams.h"
#include "core/git-access.h" // for CLOUD_HOST definitions
#include <QFile>
#include <QRegExp>
#include <QDir>
@ -1455,6 +1456,15 @@ extern "C" char *cloud_url()
return copy_qstring(filename);
}
extern "C" const char *normalize_cloud_name(const char *remote_in)
{
// replace ssrf-cloud-XX.subsurface... names with cloud.subsurface... names
// that trailing '/' is to match old code
QString ri(remote_in);
ri.replace(QRegularExpression(CLOUD_HOST_PATTERN), CLOUD_HOST_GENERIC "/");
return strdup(ri.toUtf8().constData());
}
extern "C" bool getProxyString(char **buffer)
{
if (prefs.proxy_type == QNetworkProxy::HttpProxy) {