[seahorse/feature/fix-missing-imports-of-gpgme-keys] gpgme-keyring: Also monitor .kbx in gpg homedir




commit fce9a344b98de5e328cbed1c239ae72c5fc823e1
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Fri Aug 20 00:24:58 2021 +0200

    gpgme-keyring: Also monitor .kbx in gpg homedir
    
    Seahorse monitors changes on the GPG home diretory to make sure that
    keys that get imported automagically show up as well in the UI, even as
    it's running.
    
    To make sure we don't refresh too often, the monitor filters out certain
    `GFileMonitorEvent`s, as well as making sure it only filters on the
    keyring by checking on a ".gpg" extension.
    
    This stops working from GPG 2.1 onwards however, as that version
    introduced a merged keyring, `pubring.kbx`. From that point on, our
    filter failed, as it also occluded any change in that new format.
    
    Fix this by also checking for filenames ending in ".kbx".
    
    Cleaning up the function as we're changing stuff in it anyway (and
    fixing a tiny memory leak).
    
    Fixes https://gitlab.gnome.org/GNOME/seahorse/-/issues/171

 pgp/seahorse-gpgme-keyring.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/pgp/seahorse-gpgme-keyring.c b/pgp/seahorse-gpgme-keyring.c
index 381760de..445cce90 100644
--- a/pgp/seahorse-gpgme-keyring.c
+++ b/pgp/seahorse-gpgme-keyring.c
@@ -703,24 +703,31 @@ scheduled_refresh (gpointer user_data)
 }
 
 static void
-monitor_gpg_homedir (GFileMonitor *handle, GFile *file, GFile *other_file,
-                     GFileMonitorEvent event_type, gpointer user_data)
+monitor_gpg_homedir (GFileMonitor     *file_monitor,
+                     GFile            *file,
+                     GFile            *other_file,
+                     GFileMonitorEvent event_type,
+                     void             *user_data)
 {
-       SeahorseGpgmeKeyring *self = SEAHORSE_GPGME_KEYRING (user_data);
-       gchar *name;
+    SeahorseGpgmeKeyring *self = SEAHORSE_GPGME_KEYRING (user_data);
+    g_autofree char *name = NULL;
 
-       if (event_type == G_FILE_MONITOR_EVENT_CHANGED ||
-           event_type == G_FILE_MONITOR_EVENT_DELETED ||
-           event_type == G_FILE_MONITOR_EVENT_CREATED) {
+    /* Ignore other event types */
+    if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
+        event_type != G_FILE_MONITOR_EVENT_DELETED &&
+        event_type != G_FILE_MONITOR_EVENT_CREATED)
+        return;
 
-               name = g_file_get_basename (file);
-               if (g_str_has_suffix (name, ".gpg")) {
-                       if (self->scheduled_refresh == 0) {
-                               g_debug ("scheduling refresh event due to file changes");
-                               self->scheduled_refresh = g_timeout_add (500, scheduled_refresh, self);
-                       }
-               }
-       }
+    /* If it's not the pubring.kbx or *ring.gpg (GPG <2.1), then also ignore */
+    name = g_file_get_basename (file);
+    if (!g_str_has_suffix (name, ".kbx") && !g_str_has_suffix (name, ".gpg"))
+        return;
+
+    /* Schedule a refresh if none planned yet */
+    if (self->scheduled_refresh == 0) {
+        g_debug ("scheduling refresh event due to file changes");
+        self->scheduled_refresh = g_timeout_add (500, scheduled_refresh, self);
+    }
 }
 
 static void


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