Skip to content

Commit

Permalink
[Storage]
Browse files Browse the repository at this point in the history
* limit label length
  • Loading branch information
jbleyel committed Jan 7, 2025
1 parent 8578fb3 commit 05c520d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions lib/python/Components/Storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ def __init__(self, deviceData):
self.dev_path = self.devicePoint
self.disk_path = self.dev_path

def normalizeLabel(self, label):
def getLabelLimit(self, fstype):
if "ntfs" in fstype:
return 32
elif "exfat" == fstype:
return 15
elif "ext" in fstype:
return 16
else:
return 11

def normalizeLabel(self, label, limit):
label = label.replace(" ", "_")
return "".join([ch for ch in label if ch in (ascii_letters + digits + "_")])
return "".join([ch for ch in label if ch in (ascii_letters + digits + "_")])[:limit]

def findMount(self):
if self.mount_path is None:
Expand Down Expand Up @@ -95,7 +105,7 @@ def createWipeJob(self, options=None):
def createFormatJob(self, options):
fsType = options.get("fsType", "ext4")
label = options.get("label")
label = self.normalizeLabel(label)
label = self.normalizeLabel(label, self.getLabelLimit(fsType))
job = Job(_("Formatting storage device..."))
UnmountTask(job, self)
UnmountSwapTask(job, self)
Expand Down Expand Up @@ -193,7 +203,7 @@ def createInitializeJob(self, options=None):
for index, partition in enumerate(partitions):
fsType = partition.get("fsType", "ext4")
label = partition.get("label", f"DISK_{index + 1}")
label = self.normalizeLabel(label)
label = self.normalizeLabel(label, self.getLabelLimit(fsType))
device = f"{self.devicePoint}p{index + 1}" if "mmcblk" in self.devicePoint else f"{self.devicePoint}{index + 1}"
uuid = uuids.get(device)
oldFsType = fsTypes.get(device)
Expand Down
2 changes: 1 addition & 1 deletion lib/python/Screens/DeviceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def renameActionCallback2():

def renameCallback(newName):
if newName:
newName = storageDevice.normalizeLabel(newName)
newName = storageDevice.normalizeLabel(newName, storageDevice.getLabelLimit(storageDevice.fsType))
if "extfat" == storageDevice.fsType:
cmd = f"exfatlabel {storageDevice.devicePoint} {newName}"
elif "ntfs" in storageDevice.fsType: # Not supported yet becaue you need to unmount
Expand Down

0 comments on commit 05c520d

Please sign in to comment.