[banshee] [Gio] Ensure we still have the GUdev.Device when unmounting DAPs.



commit 9378d68ff2f32952cca188fa34baa0db7a8e2c4e
Author: Alan McGovern <alan mcgovern gmail com>
Date:   Thu Aug 26 16:17:16 2010 +0100

    [Gio] Ensure we still have the GUdev.Device when unmounting DAPs.
    
    When a device is unplugged and is unmounted in GIO, we can no longer
    look up the corresponding GUdev.Device (which we need for various
    metadata about the device). We can overcome this by storing the
    GUdev.Devices in a dictionary keyed by the GIO volume. This fixes
    various crashes when disconnected different devices.

 .../Banshee.Hardware.Gio/LowLevel/Manager.cs       |   18 +++++++++---------
 .../LowLevel/RawBlockDevice.cs                     |    3 ---
 .../Banshee.Hardware.Gio/LowLevel/RawDevice.cs     |    1 -
 .../Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs  |    1 -
 .../Banshee.Hardware.Gio/LowLevel/RawVolume.cs     |    9 ++-------
 5 files changed, 11 insertions(+), 21 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 b5896ca..61a977d 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/Manager.cs
@@ -43,19 +43,22 @@ namespace Banshee.Hardware.Gio
 
         private Client client;
         private VolumeMonitor monitor;
-        private Dictionary<string, string> device_uuids;
+        // When a device is unplugged we need to be able to map the Gio.Volume to the
+        // GUDev.Device as the device will already be gone from udev. We use the native
+        // handle for the Gio volume as the key to link it to the correct gudev device.
+        private Dictionary<IntPtr, GUdev.Device> volume_device_map;
 
         public event EventHandler<MountArgs> DeviceAdded;
         public event EventHandler<MountArgs> DeviceRemoved;
 
         public Manager ()
         {
-            device_uuids = new Dictionary<string, string> ();
             client = new Client (subsystems);
             monitor = VolumeMonitor.Default;
             monitor.MountAdded += HandleMonitorMountAdded;
             monitor.MountRemoved += HandleMonitorMountRemoved;
             monitor.VolumeRemoved += HandleMonitorVolumeRemoved;
+            volume_device_map= new Dictionary<IntPtr, GUdev.Device> ();
         }
 
 #region IDisposable
@@ -74,6 +77,7 @@ namespace Banshee.Hardware.Gio
                 return;
 
             var device = GudevDeviceFromGioMount (mount);
+            volume_device_map [mount.Volume.Handle] = device;
             var h = DeviceAdded;
             if (h != null) {
                 var v = new RawVolume (mount.Volume,
@@ -81,7 +85,6 @@ namespace Banshee.Hardware.Gio
                                           new GioVolumeMetadataSource (mount.Volume),
                                           new UdevMetadataSource (device));
                 h (this, new MountArgs (HardwareManager.Resolve (new Device (v))));
-                device_uuids [mount.Volume.Name] = v.Uuid;
             }
         }
 
@@ -111,17 +114,13 @@ namespace Banshee.Hardware.Gio
         {
             var h = DeviceRemoved;
             if (h != null) {
-                var device = GudevDeviceFromGioVolume (volume);
+                GUdev.Device device;
+                volume_device_map.TryGetValue (volume.Handle, out device);
                 var v = new RawVolume (volume,
                                           this,
                                           new GioVolumeMetadataSource (volume),
                                           new UdevMetadataSource (device));
 
-                if (device_uuids.ContainsKey (volume.Name)) {
-                    v.Uuid = device_uuids [volume.Name];
-                    device_uuids.Remove (volume.Name);
-                }
-
                 h (this, new MountArgs (new Device (v)));
             }
         }
@@ -134,6 +133,7 @@ namespace Banshee.Hardware.Gio
                     continue;
                 }
 
+                volume_device_map [vol.Handle] = device;
                 var raw = new RawVolume (vol,
                                          this,
                                          new GioVolumeMetadataSource (vol),
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs
index af1dd2a..765b86e 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawBlockDevice.cs
@@ -115,9 +115,6 @@ namespace Banshee.Hardware.Gio
            get {
                return UdevMetadata.Uuid;
            }
-           set {
-               throw new NotSupportedException (); 
-           }
         }
 
         public override string Vendor {
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs
index 454507c..b9a0ccd 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawDevice.cs
@@ -100,7 +100,6 @@ namespace Banshee.Hardware.Gio
 
         public abstract string Uuid {
             get;
-            set;
         }
 
         public abstract string Vendor {
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
index bde9348..7deb3e2 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
@@ -120,7 +120,6 @@ namespace Banshee.Hardware.Gio
          
          public override string Uuid {
             get { return UdevMetadata.Uuid; }
-            set { throw new NotSupportedException (); }
          }
          
          
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs
index 8e2d0c2..f717697 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawVolume.cs
@@ -123,7 +123,7 @@ namespace Banshee.Hardware.Gio
 
         public string MountPoint {
             get {
-                return Volume.MountInstance.Root.Path;
+                return Volume.MountInstance == null ? null : Volume.MountInstance.Root.Path;
             }
         }
 
@@ -227,13 +227,8 @@ namespace Banshee.Hardware.Gio
             get { return "Product Not Implemented"; }
         }
 
-        // This is a hack. I put a set here because when we eject a volume
-        // there's no useful uuid so instead I'm going to store it, and set it
-        // based on device name. Horrible, I know.
-        private string uuid;
         public override string Uuid {
-            get { return uuid ?? UdevMetadata.Uuid; }
-            set { uuid = value; }
+            get { return Volume.Uuid ?? UdevMetadata.Uuid; }
         }
 
         public RawBlockDevice Parent {



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