Experimenting with carrying over flags across cache flush. This to solve issues when flush is cleared and target mountpoints gets lost, making it impossible to do .find_mountpoint('/') later on for instance.

This commit is contained in:
Anton Hvornum 2021-03-29 17:32:48 +02:00
parent f3907310e3
commit a0980afff1
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
1 changed files with 17 additions and 1 deletions

View File

@ -130,7 +130,20 @@ class BlockDevice():
return False
def flush_cache(self):
old_partitions = {**self.partitions}
self.part_cache = OrderedDict()
# Trigger a refresh of the cache
if len(self.partitions):
pass
# Carry over any flags from the previous partitions
for partition in old_partitions:
if partition in self.part_cache:
if self.part_cache[partition].size == old_partitions[partition].size and \
self.part_cache[partition].filesystem == old_partitions[partition].filesystem:
print('Carrying over', self.part_cache[partition].target_mountpoint)
self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint
class Partition():
def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True):
@ -237,7 +250,9 @@ class Partition():
return True if files > 0 else False
def safe_to_format(self):
if self.block_device and self.block_device.keep_partitions is True:
if self.block_device and self.block_device.keep_partitions is False:
# If we don't intend to keep any partitions on the parent block device
# We're good to format.
return True
if self.allow_formatting is False:
@ -325,6 +340,7 @@ class Partition():
else:
raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.")
# self.encrypted = False if self.filesystem != 'crypto_LUKS' else True
if self.block_device:
self.block_device.flush_cache()