summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2020-03-17 13:12:57 +0100
committerBastien Nocera <hadess@hadess.net>2020-03-17 13:12:57 +0100
commit98c4b07322ac9a2ee9d39edf5e5698c59e391ec1 (patch)
tree83c4ab3745f69d3ed1cda5f338f51f2781858f5d
parenta4df2bae2b84a4cecbe9c1f91c0801dfafd41a44 (diff)
downloadflatpak-wip/hadess/more-similar-appids.tar.gz
common: Allow version numbers in app-id for DConf migrationwip/hadess/more-similar-appids
Allow the app-id or the DConf path to finish with a digit and still be considered similar enough for DConf migration purposes. This allows the org.gnome.Rhythmbox3 app-id to migrate its /org/gnome/rhythmbox DConf path. See https://github.com/flathub/org.gnome.Rhythmbox3/pull/26
-rw-r--r--common/flatpak-utils.c45
-rw-r--r--tests/testcommon.c5
2 files changed, 43 insertions, 7 deletions
diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c
index 93d3a85d..6076c576 100644
--- a/common/flatpak-utils.c
+++ b/common/flatpak-utils.c
@@ -7515,27 +7515,58 @@ gboolean
flatpak_dconf_path_is_similar (const char *path1,
const char *path2)
{
- int i;
+ int i, i1, i2;
+ int num_components = -1;
- for (i = 0; path1[i]; i++)
+ for (i = 0; path1[i] != '\0'; i++)
{
if (path2[i] == '\0')
- return FALSE;
+ break;
if (tolower (path1[i]) == tolower (path2[i]))
- continue;
+ {
+ if (path1[i] == '/')
+ num_components++;
+ continue;
+ }
if ((path1[i] == '-' || path1[i] == '_') &&
(path2[i] == '-' || path2[i] == '_'))
continue;
- return FALSE;
+ break;
}
- if (path2[i] != '\0')
+ /* Skip over any versioning if we have at least a TLD and
+ * domain name, so 2 components */
+ /* We need at least TLD, and domain name, so 2 components */
+ i1 = i2 = i;
+ if (num_components >= 2)
+ {
+ while (isdigit (path1[i1]))
+ i1++;
+ while (isdigit (path2[i2]))
+ i2++;
+ }
+
+ if (path1[i1] != path2[i2])
return FALSE;
- return TRUE;
+ /* Both strings finished? */
+ if (path1[i1] == '\0')
+ return TRUE;
+
+ /* Maybe a trailing slash in both strings */
+ if (path1[i1] == '/')
+ {
+ i1++;
+ i2++;
+ }
+
+ if (path1[i1] != path2[i2])
+ return FALSE;
+
+ return (path1[i1] == '\0');
}
diff --git a/tests/testcommon.c b/tests/testcommon.c
index fc7f58bc..89bb7020 100644
--- a/tests/testcommon.c
+++ b/tests/testcommon.c
@@ -1144,6 +1144,11 @@ test_dconf_paths (void)
{ "/org/gnome/Builder-2/", "/org/gnome/Builder_2/", 1 },
{ "/org/gnome/Builder/", "/org/gnome/Builder", 0 },
{ "/org/gnome/Builder/", "/org/gnome/Buildex/", 0 },
+ { "/org/gnome/Rhythmbox3/", "/org/gnome/rhythmbox/", 1 },
+ { "/org/gnome/Rhythmbox3/", "/org/gnome/rhythmbox", 0 },
+ { "/org/gnome1/Rhythmbox/", "/org/gnome/rhythmbox", 0 },
+ { "/org/gnome1/Rhythmbox", "/org/gnome/rhythmbox/", 0 },
+ { "/org/gnome/Rhythmbox3plus/", "/org/gnome/rhythmbox/", 0 },
};
int i;