Added an option to force-flush a blockdevice cache. creating a new Filesystem() now triggers a flush of the cache since all partitions are removed. There shouldn't be any harm in even bypassing the cache, but it's there for a few reasons.

This commit is contained in:
Anton Hvornum 2021-03-21 17:25:18 +01:00
parent c8470b81a6
commit 298ed31531
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
1 changed files with 4 additions and 0 deletions

View File

@ -129,6 +129,9 @@ class BlockDevice():
return True
return False
def flush_cache(self):
self.part_cache = OrderedDict()
class Partition():
def __init__(self, path, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True):
if not part_id:
@ -366,6 +369,7 @@ class Filesystem():
log(f'Wiping {self.blockdevice} by using partition format {self.mode}', level=LOG_LEVELS.Debug)
if self.mode == GPT:
if self.raw_parted(f'{self.blockdevice.device} mklabel gpt').exit_code == 0:
self.blockdevice.flush_cache()
return self
else:
raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt')