[gdm] libgdm: filter out sessions with duplicate names



commit c98ea6a4dc807aaf261eab6025ba3c3e5662d51c
Author: zhengqiang130 <qzheng suse com>
Date:   Mon Oct 29 17:11:32 2018 +0800

    libgdm: filter out sessions with duplicate names
    
    Right now if two session files have the same translated name, the login
    screen will show both of them.  There's no way the user can know which
    session does which, so that's not a great user experience. Furthermore,
    in the face of symlinks, both sessions truely could be identical.
    
    This commit filters out the duplicates, so only one shows in the list.
    
    Closes https://gitlab.gnome.org/GNOME/gdm/issues/437

 libgdm/gdm-sessions.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/libgdm/gdm-sessions.c b/libgdm/gdm-sessions.c
index 7badafe1..afbc5c09 100644
--- a/libgdm/gdm-sessions.c
+++ b/libgdm/gdm-sessions.c
@@ -111,6 +111,14 @@ key_file_is_relevant (GKeyFile     *key_file)
         return TRUE;
 }
 
+static gboolean
+find_session_with_same_name (const char     *id,
+                             GdmSessionFile *session,
+                             const char     *translated_name)
+{
+        return g_strcmp0 (session->translated_name, translated_name) == 0;
+}
+
 static void
 load_session_file (const char              *id,
                    const char              *path)
@@ -118,7 +126,7 @@ load_session_file (const char              *id,
         GKeyFile          *key_file;
         GError            *error;
         gboolean           res;
-        GdmSessionFile    *session;
+        GdmSessionFile    *session, *session_with_same_name;
 
         key_file = g_key_file_new ();
 
@@ -154,6 +162,13 @@ load_session_file (const char              *id,
         session->translated_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", 
NULL, NULL);
         session->translated_comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, 
"Comment", NULL, NULL);
 
+        session_with_same_name = g_hash_table_find (gdm_available_sessions_map,
+                                                    (GHRFunc) find_session_with_same_name,
+                                                    session->translated_name);
+
+        if (session_with_same_name != NULL)
+                g_hash_table_remove (gdm_available_sessions_map, session_with_same_name->id);
+
         g_hash_table_insert (gdm_available_sessions_map,
                              g_strdup (id),
                              session);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]