Added some more failsafe's to the Partition() object.

This commit is contained in:
Anton Hvornum 2021-02-07 15:09:40 +01:00
parent 9767095258
commit 759b778743
1 changed files with 11 additions and 8 deletions

View File

@ -120,20 +120,23 @@ class Partition():
part_id = os.path.basename(path) part_id = os.path.basename(path)
self.path = path self.path = path
self.part_id = part_id self.part_id = part_id
self.mountpoint = None self.mountpoint = mountpoint
self.filesystem = filesystem # TODO: Autodetect if we're reusing a partition self.filesystem = filesystem
self.size = size # TODO: Refresh? self.size = size # TODO: Refresh?
self.encrypted = encrypted self.encrypted = encrypted
if mountpoint: if mountpoint:
self.mount(mountpoint) self.mount(mountpoint)
if not self.mountpoint: partition_info = get_partition_info(self.path)
# As a last step, check if we've mounted outside of the script
partition_info = get_partition_info(self.path) if self.mountpoint != partition_info['target'] and mountpoint:
self.mountpoint = partition_info['target'] raise DiskError(f"{self} was given a mountpoint but the actual mountpoint differs: {partition_info['target']}")
if partition_info['fstype'] != self.filesystem and filesystem: if partition_info['fstype'] != self.filesystem and filesystem:
raise DiskError(f"{self} was given a filesystem format, but a existing format was detected: {partition_info['fstype']}") raise DiskError(f"{self} was given a filesystem format, but a existing format was detected: {partition_info['fstype']}")
self.mountpoint = partition_info['target']
self.filesystem = partition_info['fstype']
def __repr__(self, *args, **kwargs): def __repr__(self, *args, **kwargs):
if self.encrypted: if self.encrypted: