Skip to content

Commit

Permalink
[Hotplug]
Browse files Browse the repository at this point in the history
* improve add new device
  • Loading branch information
jbleyel committed Jan 7, 2025
1 parent a38a9f4 commit 0f78c67
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/python/Plugins/SystemPlugins/Hotplug/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self):
self.removeTimer.callback.append(self.processRemoveDevice)
self.deviceData = []
self.addedDevice = []
self.callMount = False

def processAddDevice(self):
self.addTimer.stop()
Expand Down Expand Up @@ -127,7 +128,9 @@ def processAddDevice(self):
fstab = fileReadLines("/etc/fstab")
fstabDevice = [x.split()[1] for x in fstab if ID_FS_UUID in x and EXPANDER_MOUNT not in x]
if fstabDevice and fstabDevice[0] not in mounts: # Check if device is already in fstab and if the mountpoint not used
Console().ePopen("/bin/mount -a")
if not exists(fstabDevice[0]):
mkdir(fstabDevice[0], 0o755)
self.callMount = True
notFound = False
self.newCount += 1

Expand All @@ -138,7 +141,9 @@ def processAddDevice(self):
newFstab = [x for x in fstab if f"UUID={ID_FS_UUID}" not in x and EXPANDER_MOUNT not in x]
newFstab.append(f"UUID={ID_FS_UUID} {mountPointHdd} {ID_FS_TYPE} defaults 0 0")
fileWriteLines("/etc/fstab", newFstab)
Console().ePopen("/bin/mount -a")
if not exists(mountPointHdd):
mkdir(mountPoint, 0o755)
self.callMount = True
notFound = False
self.newCount += 1

Expand Down Expand Up @@ -168,19 +173,19 @@ def newDeviceCallback(answer):
newFstab = [x for x in fstab if f"UUID={ID_FS_UUID}" not in x and EXPANDER_MOUNT not in x]
newFstab.append(f"UUID={ID_FS_UUID} {mountPoint} {ID_FS_TYPE} defaults 0 0")
fileWriteLines("/etc/fstab", newFstab)
Console().ePopen("/bin/mount -a")
self.callMount = True
elif answer == 4:
knownDevices.append(f"{ID_FS_UUID}:{mountPointHdd}")
newFstab = [x for x in fstab if f"UUID={ID_FS_UUID}" not in x and EXPANDER_MOUNT not in x]
newFstab.append(f"UUID={ID_FS_UUID} {mountPointHdd} {ID_FS_TYPE} defaults 0 0")
fileWriteLines("/etc/fstab", newFstab)
Console().ePopen("/bin/mount -a")
self.callMount = True
elif answer == 5:
knownDevices.append(f"{ID_FS_UUID}:{mountPointDevice}")
newFstab = [x for x in fstab if f"UUID={ID_FS_UUID}" not in x and EXPANDER_MOUNT not in x]
newFstab.append(f"UUID={ID_FS_UUID} {mountPointDevice} {ID_FS_TYPE} defaults 0 0")
fileWriteLines("/etc/fstab", newFstab)
Console().ePopen("/bin/mount -a")
self.callMount = True
if answer in (1, 3, 4, 5):
fileWriteLines("/etc/udev/known_devices", knownDevices)
self.addedDevice.append((DEVNAME, DEVPATH, ID_MODEL))
Expand All @@ -207,6 +212,9 @@ def newDeviceCallback(answer):
self.addTimer.start(1000)
else:
if self.newCount:
if self.callMount:
self.callMount = False
Console().ePopen("/bin/mount -a")
self.newCount = 0
for device, physicalDevicePath, model in self.addedDevice:
harddiskmanager.addHotplugPartition(device, physicalDevicePath, model=model)
Expand Down

0 comments on commit 0f78c67

Please sign in to comment.