summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhaedrus Leeds <mwleeds@protonmail.com>2021-11-02 10:49:25 -0700
committerAlexander Larsson <alexander.larsson@gmail.com>2021-11-15 09:54:56 +0100
commit62e09b406b8a7fb517c294d2c0b149a83f2cc64b (patch)
tree05db8aaa7dd9433bc26dc5d234c99d8d31e05f97
parentf3214c59d2f687e47ab5d9a74d8a3ef45f8e0105 (diff)
downloadflatpak-62e09b406b8a7fb517c294d2c0b149a83f2cc64b.tar.gz
search: Don't strip .desktop suffix overzealously
This commit changes the search command to properly output the app ID for IDs that end in .desktop, e.g. to print org.telegram.desktop rather than org.telegram. Fixes https://github.com/flatpak/flatpak/issues/4535
-rw-r--r--app/flatpak-builtins-search.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/app/flatpak-builtins-search.c b/app/flatpak-builtins-search.c
index d7f2a4c1..d2a04895 100644
--- a/app/flatpak-builtins-search.c
+++ b/app/flatpak-builtins-search.c
@@ -194,6 +194,33 @@ as_app_equal (AsApp *app1, AsApp *app2)
}
#endif
+/* This returns the app ID with the ".desktop" suffix stripped. In most cases
+ * that is what as_app_get_id_filename() does, but if the ID actually ends in
+ * .desktop it is stripped anyway and e.g. "org.telegram" is returned instead
+ * of "org.telegram.desktop" (which is a bug in appstream-glib). See
+ * https://github.com/hughsie/appstream-glib/issues/420 and
+ * https://github.com/flatpak/flatpak/issues/4535
+ */
+static const char *
+_app_get_id_no_suffix (AsApp *app)
+{
+ const gchar *id_with_suffix = NULL;
+ const gchar *id_stripped = NULL;
+ id_with_suffix = as_app_get_id_no_prefix (app);
+ id_stripped = as_app_get_id_filename (app);
+ if (flatpak_is_valid_name (id_stripped, -1, NULL))
+ return id_stripped;
+ else
+ {
+ g_autofree char *id_with_desktop = g_strconcat (id_stripped, ".desktop", NULL);
+ if (flatpak_is_valid_name (id_with_desktop, -1, NULL) &&
+ g_strcmp0 (id_with_suffix, id_with_desktop) == 0)
+ return id_with_suffix;
+ else
+ return id_stripped;
+ }
+}
+
static int
compare_apps (MatchResult *a, AsApp *b)
{
@@ -210,7 +237,7 @@ static void
print_app (Column *columns, MatchResult *res, FlatpakTablePrinter *printer)
{
const char *version = as_app_get_version (res->app);
- const char *id = as_app_get_id_filename (res->app);
+ const char *id = _app_get_id_no_suffix (res->app);
const char *name = as_app_get_localized_name (res->app);
const char *comment = as_app_get_localized_comment (res->app);
guint i;
@@ -307,7 +334,7 @@ flatpak_builtin_search (int argc, char **argv, GCancellable *cancellable, GError
guint score = as_app_search_matches (app, search_text);
if (score == 0)
{
- const char *app_id = as_app_get_id_filename (app);
+ const char *app_id = _app_get_id_no_suffix (app);
if (strcasestr (app_id, search_text) != NULL)
score = 50;
else