LXC Storage Parsing Fragility #11
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lines 2225-2260: The column index parsing assumes fixed format:
columns = fs_line.split()
if len(columns) >= 6:
total_space = self._parse_size(columns[2]) # Fragile!
Improvement - use regex for robustness:
Match: filesystem size used avail use% mountpoint
match = re.match(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)%\s+(.+)', fs_line)
if match:
_, total, used, avail, percent, mountpoint = match.groups()
total_space = self._parse_size(total)
# ...