File 0001-Detect-CDROM-media-changes-using-ID_FD_UUID-udev-pro.patch of Package thunar

From 08fd8e74ff93ddadab908d00135770c0a59861bb Mon Sep 17 00:00:00 2001
From: Franck Bui <fbui@suse.com>
Date: Mon, 26 Jan 2026 09:59:38 +0100
Subject: [PATCH 1/1] Detect CDROM media changes using ID_FD_UUID udev property

Thunar currently interprets every "change" uevent from a CD-ROM device as
indicating that the media has changed, even when the uevent carries no
meaningful updates relevant to the application. This leads to incorrect
behavior, such as unnecessary mounting attempts triggered by synthetic uevents
(via `udevadm trigger /dev/sr0`) or unrelated system events.

A notable consequence is inconsistent handling of unmounts: after a user
explicitly unmounts a CDROM via the GUI, Thunar immediately remounts it due to
spurious uevents.

Since systemd v258, applying ACLs to seat devices involves triggering
uevents. When switching TTYs, these uevents cause Thunar to attempt mounting the
drive. However, with the active seat changed during the TTY switch, the mount
requires authentication, which prompts the user upon returning to the graphical
session.

To address this issue, introduce a check in the uevent handler to verify if the
filesystem UUID (ID_FS_UUID) has actually changed before treating a "change"
event as a media update. This ensures Thunar only reacts to genuine media
insertions, ignoring irrelevant uevents.

The FS UUID is stored in a new ThunarApplication field (cdrom_media_fs_uuid) and
updated only on confirmed changes. If no media is present, the stored UUID is
cleared.
---
 thunar/thunar-application.c | 40 ++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index a8de3549..5398c3ec 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -247,6 +247,7 @@ struct _ThunarApplication
   GSList *volman_udis;
   guint   volman_idle_id;
   guint   volman_watch_id;
+  gchar  *cdrom_media_fs_uuid;
 #endif
 
   GList                         *files_to_launch;
@@ -406,6 +407,8 @@ thunar_application_startup (GApplication *gapp)
    * or disconnected from the computer */
   g_signal_connect (application->udev_client, "uevent",
                     G_CALLBACK (thunar_application_uevent), application);
+
+  application->cdrom_media_fs_uuid = NULL;
 #endif
 
   thunar_application_dbus_init (application);
@@ -455,6 +458,8 @@ thunar_application_shutdown (GApplication *gapp)
 
   /* disconnect from the udev client */
   g_object_unref (application->udev_client);
+
+  g_free(application->cdrom_media_fs_uuid);
 #endif
 
   /* drop any running "show dialogs" timer */
@@ -1068,6 +1073,33 @@ thunar_application_launch (ThunarApplication     *application,
 
 
 #ifdef HAVE_GUDEV
+static gboolean has_cdrom_media_changed(GUdevDevice       *device,
+					ThunarApplication *application)
+{
+  const gchar *media_fs_uuid = NULL;
+
+  /* check if the device is a CD drive */
+  if (!g_udev_device_get_property_as_boolean (device, "ID_CDROM"))
+	  return FALSE;
+
+  /* check if the CD drive has a media */
+  if (!g_udev_device_get_property_as_boolean (device, "ID_CDROM_MEDIA")) {
+	  g_free(application->cdrom_media_fs_uuid);
+	  application->cdrom_media_fs_uuid = NULL;
+	  return FALSE;
+  }
+
+  media_fs_uuid = g_udev_device_get_property (device, "ID_FS_UUID");
+
+  if (g_strcmp0 (application->cdrom_media_fs_uuid, media_fs_uuid) == 0)
+	  return FALSE;
+
+  g_free(application->cdrom_media_fs_uuid);
+  application->cdrom_media_fs_uuid = g_strdup(media_fs_uuid);
+
+  return TRUE;
+}
+
 static void
 thunar_application_uevent (GUdevClient       *client,
                            const gchar       *action,
@@ -1075,8 +1107,6 @@ thunar_application_uevent (GUdevClient       *client,
                            ThunarApplication *application)
 {
   const gchar *sysfs_path;
-  gboolean     is_cdrom = FALSE;
-  gboolean     has_media = FALSE;
   GSList      *lp;
 
   _thunar_return_if_fail (G_UDEV_IS_CLIENT (client));
@@ -1088,13 +1118,9 @@ thunar_application_uevent (GUdevClient       *client,
   /* determine the sysfs path of the device */
   sysfs_path = g_udev_device_get_sysfs_path (device);
 
-  /* check if the device is a CD drive */
-  is_cdrom = g_udev_device_get_property_as_boolean (device, "ID_CDROM");
-  has_media = g_udev_device_get_property_as_boolean (device, "ID_CDROM_MEDIA");
-
   /* distinguish between "add", "change" and "remove" actions, ignore "move" */
   if (g_strcmp0 (action, "add") == 0
-      || (is_cdrom && has_media && g_strcmp0 (action, "change") == 0))
+      || (has_cdrom_media_changed(device, application) && g_strcmp0 (action, "change") == 0))
     {
       /* only insert the path if we don't have it already */
       if (g_slist_find_custom (application->volman_udis, sysfs_path,
-- 
2.51.0

openSUSE Build Service is sponsored by