Commits

Byron Clark committed 9819b69

Keep a last state for devices to prevent remount on unmount.

refs issue 1

  • Participants
  • Parent commits 435512e

Comments (0)

Files changed (1)

File udiskie/mount.py

 
 import udiskie.device
 
+class DeviceState:
+    def __init__(self, mounted):
+        self.mounted = mounted
+
+
 class AutoMounter:
     def __init__(self, bus=None):
         self.log = logging.getLogger('udiskie.mount.AutoMounter')
+        self.last_device_state = {}
 
         if not bus:
             from dbus.mainloop.glib import DBusGMainLoop
 
     def device_changed(self, device):
         self.log.debug('device changed: %s' % (device,))
-        device = udiskie.device.Device(self.bus, device)
-        if not device.is_mounted():
-            self._mount_device(device)
+        last_state = self.last_device_state.get(device)
+        udiskie_device = udiskie.device.Device(self.bus, device)
+        if (not last_state) or (not last_state.mounted):
+            self._mount_device(udiskie_device)
+        self.last_device_state[device] = DeviceState(udiskie_device.is_mounted())
 
 
 def cli(args):