From 0c7f803b592a2f472714c5e7c97b92515aef0620 Mon Sep 17 00:00:00 2001
From: Ondrej Holy <oholy@redhat.com>
Date: Wed, 25 Oct 2017 20:28:22 +0200
Subject: [PATCH] mtp: Fix volume removal with current udev behavior

UDev events for devices without ID_MTP_DEVICE property are ignored.
Although ID_MTP_DEVICE seems don't have to be set for device when removing
and thus the volume is not removed. Let's ignore ID_MTP_DEVICE when removing.

https://bugzilla.gnome.org/show_bug.cgi?id=789491
---
 monitor/mtp/gmtpvolumemonitor.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/monitor/mtp/gmtpvolumemonitor.c b/monitor/mtp/gmtpvolumemonitor.c
index 50e37cfe..bfd9e29f 100644
--- a/monitor/mtp/gmtpvolumemonitor.c
+++ b/monitor/mtp/gmtpvolumemonitor.c
@@ -208,17 +208,12 @@ on_uevent (GUdevClient *client, gchar *action, GUdevDevice *device, gpointer use
 
   g_debug ("on_uevent: action=%s, device=%s", action, g_udev_device_get_device_file(device));
 
-  /* filter out uninteresting events */
-  if (!g_udev_device_has_property (device, "ID_MTP_DEVICE"))
-    {
-      g_debug ("on_uevent: discarding, not ID_MTP");
-      return;
-    }
-
-  if (strcmp (action, "add") == 0)
-     gudev_add_device (monitor, device, TRUE); 
-  else if (strcmp (action, "remove") == 0)
-     gudev_remove_device (monitor, device); 
+  if (g_strcmp0 (action, "add") == 0 && g_udev_device_has_property (device, "ID_MTP_DEVICE"))
+    gudev_add_device (monitor, device, TRUE);
+  else if (g_strcmp0 (action, "remove") == 0 && g_udev_device_get_device_file (device) != NULL)
+    gudev_remove_device (monitor, device);
+  else
+    g_debug ("on_uevent: discarding");
 }
 
 static void
-- 
2.17.1

