[banshee] Mtp: Ignore mount/unmount events to fix device load (bgo#729438)



commit 0eb6554ff08efd209fac79d41e43fb5bc52c7b98
Author: Nicholas Little <arealityfarbetween googlemail com>
Date:   Thu May 15 16:47:28 2014 +0200

    Mtp: Ignore mount/unmount events to fix device load (bgo#729438)
    
    When plugging an MTP device into the system, banshee must
    unmount it to be able to use it. Since the hardware manager
    emits signals when a device is unmounted, this causes banshee
    to unmap a device that it is in the middle of configuring.
    
    This patch changes the signals that GIO Manager watches on
    GNU/Linux systems from VolumeAdded, MountAdded and MountRemoved
    to VolumeAdded and VolumeRemoved. This has the added benefit
    that users with automount disabled have their devices recognised.
    
    Signed-off-by: Andrés G. Aragoneses <knocte gmail com>

 .../Banshee.Hardware.Gio/LowLevel/Manager.cs       |   54 +++++++++++---------
 .../Banshee.Dap.MassStorage/MassStorageSource.cs   |    7 ++-
 2 files changed, 35 insertions(+), 26 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs 
b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
index f635b93..42efeaa 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
@@ -3,8 +3,10 @@
 //
 // Author:
 //   Alex Launi <alex launi gmail com>
+//   Nicholas Little <arealityfarbetween googlemail com>
 //
 // Copyright (c) 2010 Alex Launi
+// Copyright (c) 2014 Nicholas Little
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -57,6 +59,7 @@ namespace Banshee.Hardware.Gio
             monitor = VolumeMonitor.Default;
             monitor.MountAdded += HandleMonitorMountAdded;
             monitor.MountRemoved += HandleMonitorMountRemoved;
+            monitor.VolumeAdded += HandleMonitorVolumeAdded;
             monitor.VolumeRemoved += HandleMonitorVolumeRemoved;
             volume_device_map= new Dictionary<IntPtr, GUdev.Device> ();
         }
@@ -71,38 +74,22 @@ namespace Banshee.Hardware.Gio
 
         void HandleMonitorMountAdded (object o, MountAddedArgs args)
         {
-            // Manually get the mount as gio-sharp translates it to the wrong managed object
-            // TODO: check if this workaround is still needed
-            var mount = GLib.MountAdapter.GetObject ((GLib.Object) args.Args [0]);
-            if (mount.Volume == null)
-                return;
-
-            var device = GudevDeviceFromGioMount (mount);
-            if (device == null) {
-                Hyena.Log.Debug (string.Format ("Tried to mount {0}/{1} with no matching udev device", 
mount.Volume.Name, mount.Volume.Uuid));
-                return;
-            }
-
-            volume_device_map [mount.Volume.Handle] = device;
-            var h = DeviceAdded;
-            if (h != null) {
-                var v = new RawVolume (mount.Volume,
-                                          this,
-                                          new GioVolumeMetadataSource (mount.Volume),
-                                          new UdevMetadataSource (device));
-                h (this, new MountArgs (HardwareManager.Resolve (new Device (v))));
-            }
+            Hyena.Log.Debug ("(Ignored) MountAdded event received");
         }
 
         void HandleMonitorMountRemoved (object o, MountRemovedArgs args)
         {
-            // Manually get the mount as gio-sharp translates it to the wrong managed object
-            var mount = GLib.MountAdapter.GetObject ((GLib.Object) args.Args [0]);
-            if (mount.Volume == null) {
+            Hyena.Log.Debug ("(Ignored) MountRemoved event received");
+        }
+
+        private void HandleMonitorVolumeAdded (object o, VolumeAddedArgs args)
+        {
+            var volume = GLib.VolumeAdapter.GetObject ((GLib.Object) args.Args [0]);
+            if (volume == null) {
                 return;
             }
 
-            VolumeRemoved (mount.Volume);
+            VolumeAdded (volume);
         }
 
         void HandleMonitorVolumeRemoved (object o, VolumeRemovedArgs args)
@@ -115,6 +102,23 @@ namespace Banshee.Hardware.Gio
             VolumeRemoved (volume);
         }
 
+        private void VolumeAdded (GLib.IVolume volume)
+        {
+            var device = GudevDeviceFromGioVolume (volume);
+            volume_device_map [volume.Handle] = device;
+            var h = DeviceAdded;
+            if (h != null) {
+                if (device == null) {
+                    Hyena.Log.Debug (string.Format ("Tried to mount {0}/{1} with no matching udev device", 
volume.Name, volume.Uuid));
+                    return;
+                }
+                var v = new RawVolume (volume,
+                    this,
+                    new GioVolumeMetadataSource (volume),
+                    new UdevMetadataSource (device));
+                h (this, new MountArgs (HardwareManager.Resolve (new Device (v))));
+            }
+        }
 
         void VolumeRemoved (GLib.IVolume volume)
         {
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs 
b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
index 3c54f36..4e8ab6d 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
@@ -63,10 +63,15 @@ namespace Banshee.Dap.MassStorage
             base.DeviceInitialize (device);
 
             volume = device as IVolume;
-            if (volume == null || !volume.IsMounted || (usb_device = volume.ResolveRootUsbDevice ()) == 
null) {
+
+            if (volume == null || (usb_device = volume.ResolveRootUsbDevice ()) == null) {
                 throw new InvalidDeviceException ();
             }
 
+            if (volume.CanMount) {
+                volume.Mount ();
+            }
+
             ms_device = DeviceMapper.Map (this);
             try {
                 if (ms_device.ShouldIgnoreDevice () || !ms_device.LoadDeviceConfiguration ()) {


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